【问题标题】:Powershell v5.1 : Copy from share server to local folder on a remote PCPowershell v5.1:从共享服务器复制到远程 PC 上的本地文件夹
【发布时间】:2020-04-22 21:06:42
【问题描述】:

我必须管理大约 10 台运行窗口 10 的 PC。 我需要将一些软件从共享文件夹(\company\folder 或 \MyPC\SharedFolder)复制到那些 PC 手动远程是可以的,但是,将项目从共享文件夹复制到 10 台 PC 既费时又无聊。 我发现使用 Invoke-commandcopy-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或者使用cddir看看有没有其他问题。
  • 我尝试使用Enter-PSSessionTest-Path,结果是Fasle。我在我的电脑上用Test-Path 测试,结果也是False。我猜想通过本地局域网与Network sharing 相关的问题。但是,我不知道我需要为共享文件夹配置什么?
  • 我更新更多信息,我的电脑已经更新规则,我使用测试路径,结果是True,但是结果仍然是access denied,错误UnauthorizedAccessException

标签: powershell windows-10 credentials powershell-5.0


【解决方案1】:

最后,我找到了解决方案,这是解决此问题的方法。
Copy-Item -ToSession $session -Path \\CompanyFolder\Shared\Samples.zip -Destination D:\ -Recurse
更多信息可以找到here

【讨论】:

    猜你喜欢
    • 2016-09-13
    • 2011-02-21
    • 2022-10-14
    • 2019-08-23
    • 1970-01-01
    • 2012-02-17
    • 2022-01-28
    • 1970-01-01
    • 2023-01-19
    相关资源
    最近更新 更多