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