【发布时间】:2015-03-31 20:15:47
【问题描述】:
我在尝试使用 PSCredentials 通过 Powershell 自动登录到我的服务器上的共享时感到困惑。
这是我当前使用的代码,没有使用 PSCredentials...
#Login to server to copy installer files to desktop
Remove-PSDrive P
New-PSDrive -Name P -PSProvider FileSystem -Root \\192.168.1.85\Users2\Ross\Documents\Powershell -Credential Ross
#Copies installer files from server to the local desktop
Copy-Item -Path \\192.168.1.85\Users2\Ross\Documents\Powershell\ccsetup502.exe -Destination C:\Users\Ross\Desktop
#Executes copied installers
Start-Process C:\Users\Ross\Desktop\ccsetup502.exe -ArgumentList "/S" -Wait -Verb RunAs
#Deletes leftover installer files
Remove-Item C:\Users\Ross\Desktop\ccsetup502.exe
这是我用来提供帮助的网站,但无论我尝试以哪种方式将其应用于我自己的脚本,它都无法正常工作?
http://geekswithblogs.net/Lance/archive/2007/02/16/106518.aspx
提前致谢!
罗斯
【问题讨论】:
-
您遇到了什么错误,在哪一行 - New-PSDrive 行还是 Copy-Item 行?
-
Ross不是凭证对象。您可以使用-Credential (Get-Credential Ross),它会提示您输入用户名和密码(用户名预先填写为“Ross”)。但了解@KeithHill 要求的信息会很有帮助。
标签: windows shell powershell powershell-3.0