gpt4 book ai didi

shell - New-PSDrive:找不到网络路径

转载 作者:行者123 更新时间:2023-12-02 23:39:44 24 4
gpt4 key购买 nike

我在使用New-PSDrive连接到远程服务器时遇到问题。远程服务器是基于Windows的,并且只有userA有权写。

如此说来,以下代码将引发“访问被拒绝”错误:

Access to the path '$remoteServerPath' is denied on line3



码:
New-PSDrive -Name remote -Root $remoteServerPath -PSProvider FileSystem 
$destination = [IO.Path]::Combine('remote:', $fileName)
Copy-Item -Path $source -Destination $destination -Force

现在,我试图包括凭据信息,但是出现了另一个错误!

The network path was not found on line3


$secpass = ConvertTo-SecureString 'myPassword' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ('domain\userA', $secpass)
New-PSDrive -Name remote -Root $remoteServerPath-PSProvider FileSystem -Credential $cred
$destination = [IO.Path]::Combine('remote:', $fileName)
Copy-Item -Path $source -Destination $destination -Force

有人可以帮我吗? Powershell版本5

最佳答案

为什么要为此任务创建PSDrive?

& NET USE Z: \\server\path /user:domain\UserA 'PASSWORD'
Copy-Item -Path $Source -Destination 'Z:\' -Force
& NET USE Z: /D

如果您有他们的纯文本密码,这应该可以正常工作。

关于shell - New-PSDrive:找不到网络路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45336606/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com