【发布时间】:2020-04-22 21:06:42
【问题描述】:
我必须管理大约 10 台运行窗口 10 的 PC。
我需要将一些软件从共享文件夹(\company\folder 或 \MyPC\SharedFolder)复制到那些 PC
手动远程是可以的,但是,将项目从共享文件夹复制到 10 台 PC 既费时又无聊。
我发现使用 Invoke-command 和 copy-item 可以帮助我更快地做到这一点。但是,我收到错误 Access is denied
$usr = "UserName"
$pw = convertto-securestring -AsPlainText -Force -String Password
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "$usr",$pw
For ($i=1; $i -lt 11; $i++)
{
$computerName=""
if($i -lt 10) {
$computerName="PC000$i"
} else {
$computerName="PC00$i"
}
Write-host "Copy on $computerName"
$session = New-PSSession -ComputerName "ServerA" -Credential $creds -Authentication Kerberos
Invoke-Command -Session $session -ScriptBlock { Copy-Item \\CompanyFolder\Shared\Sample.zip D:\Shared }
}
下面是错误
Access is denied
+ CategoryInfo : PermissionDenied: (\\CompanyFolder\Shared\Sample.zip:String) [Copy-Item], UnauthorizedAccessException
+ FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
+ PSComputerName : PC0007
Cannot find path '\\CompanyFolder\Shared\Sample.zip' because it does not exist.
+ CategoryInfo : ObjectNotFound: (\\CompanyFolder\Shared\Sample.zip:String) [Copy-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand
+ PSComputerName : PC0007
我在here 搜索并找到了类似的问题,但它无法解决我的问题。你有什么想法吗?
【问题讨论】:
-
您登录的用户是否拥有共享的访问权限?顺便提一句。您正在创建 PSSessoins,但没有删除它们。使用
Remove-PSSession摆脱它们。 -
感谢您的来信。用户对网络共享文件夹和本地文件夹拥有完全权限。如果我理解你的要求
-
尝试使用
Enter-PSSession将$Session用作交互式CLI。这样你可以Test-Path或者使用cd和dir看看有没有其他问题。 -
我尝试使用
Enter-PSSession和Test-Path,结果是Fasle。我在我的电脑上用Test-Path测试,结果也是False。我猜想通过本地局域网与Network sharing相关的问题。但是,我不知道我需要为共享文件夹配置什么? -
我更新更多信息,我的电脑已经更新规则,我使用测试路径,结果是
True,但是结果仍然是access denied,错误UnauthorizedAccessException
标签: powershell windows-10 credentials powershell-5.0