我正在尝试将文件复制到我的用户有权限的UNC文件名,但没有传统的驱动器号映射。 PSVersion 5.0.10586.11
# 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
答案 0 :(得分:1)
Copy-Item具有支持它的PS提供程序的Credential参数。如图所示,FileSystem提供程序没有。你必须使用New-psdrive。