首页 > 解决方案 > 带有文件共享的 Powershell Invoke-Command

问题描述

我有一个这样的 Powershell 脚本:

param([string]$zipFileLocation)
if([string]::IsNullOrEmpty($zipFileLocation))
{
 write-host "No location provided" 
 return $false
}

write-host "Location of zip: $zipFileLocation" 
write-host "Test-path result: $(test-path($zipFileLocation))"
write-host "END OF SCRIPT"

当我在本地运行此脚本时,使用参数 '\Server\Share',Test-Path 返回 true 并且一切正常。即当我运行'.\TestScript.ps1 -zipFileLocation '\\Server\Share'它按预期工作。

但是,如果我像这样运行命令:

$remsession1 = New-PSSession -credential $credential -ComputerName $ServerName
$UnzipPackageResult= Invoke-Command -session $remsession1 -FilePath C:\Test\TestScript.ps1 -ArgumentList '\\Server\Share' 

然后脚本中的“测试路径”返回$false并出现UnauthorizedAccessException错误。我不明白为什么。

提供的凭据在服务器上确实具有管理员权限。有什么想法吗?

标签: powershell

解决方案


推荐阅读