2016-08-14 2 views
0

私のユーザーに許可が与えられていて、従来のドライブ文字マッピングがないUNCファイルにファイルをコピーしようとしています。スクリプトを実行PSVersion 5.0.10586.11コピーアイテムのエラーで-Credentialを使用する

# Get and store the password in an encrypted file. Do this once only. 
# (Get-Credential).Password | ConvertFrom-SecureString | Out-File .\my_secret.txt" 

$user = "me" 
$file = ".\my_secret.txt" 
$cred = New-Object -TypeName System.Management.Automation.PSCredential ` 
-ArgumentList $user, (Get-Content $file | ConvertTo-SecureString) 

Copy-Item -Credential $cred .\list.txt "\\zeplin.nowhere.org\data\docs\log" 

Copy-Item-Credentialをサポートしていないことを示唆しているようです。私がしなければ、私はむしろNew-PSDriveと新しいドライブ文字のマッピングを作成しないでください。 Get-Help Copy-Itemを使用すると、-Credentialsパラメータがサポートされていることがわかります。次のエラーメッセージが返されます。

The FileSystem provider supports credentials only on the New-PSDrive cmdlet. Perform the operation again without specifying 
credentials. 
PS C:\Users\me> .\t.ps1 
At C:\Users\me\t.ps1:8 char:1 
+ Copy-Item -Credential $cred .\list.txt "\\zeplin.nowhere.org\data\docs ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotImplemented: (:) [], PSNotSupportedException 
    + FullyQualifiedErrorId : NotSupported 

答えて

1

Copy-Itemには、それをサポートするPSプロバイダのCredentialパラメータがあります。 FileSystemプロバイダは、示されているとおり、そうではありません。 New-psdriveを使う必要があります。

関連する問題