2017-07-26 29 views
0

New-PSDriveを使用してリモートサーバーに接続する際に問題が発生しています。リモートサーバーはWindowsベースであり、書き込めるのはuserAのみです。New-PSDrive:ネットワークパスが見つかりません

次のコードは、エラーを「アクセス拒否」スロー、と言って:

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 Ver。 5

答えて

1

なぜこのタスク用のPSDriveを作成していますか?あなたは自分の平文パスワードを取得している場合

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

、これはうまく動作するはずです。

+0

私は、次のエラーを取得しています: 「FileSystemプロバイダーのみ新-PSDriveコマンドレットの資格情報をサポートしています 指定した資格情報なしで操作を再実行してください。」そのまま、この例を使用して@Adrian – Adrian

+0
+0

New-PSDriveのみが資格情報をサポートしているようですが、copy-itemはサポートしていません。それは私のPS版のためですか? (5) – Adrian

関連する問題