首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Powershell PS凭据

Powershell PS凭据
EN

Stack Overflow用户
提问于 2015-02-02 05:48:56
回答 2查看 150关注 0票数 0

当我尝试使用PSCredentials通过Powershell自动登录到我的服务器上的共享时,我感到困惑。

这是我目前使用的代码,没有使用PSCredentials...

代码语言:javascript
复制
#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

提前感谢!

罗斯

EN

回答 2

Stack Overflow用户

发布于 2015-02-04 09:44:15

尝尝这个。它将提示您输入凭证,但如果您愿意,也可以创建它们并将其存储在变量中。

代码语言:javascript
复制
#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 (Get-Credential)
#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
票数 1
EN

Stack Overflow用户

发布于 2015-02-06 05:00:38

经过一些坚持不懈的努力我终于解决了这个问题。

可能值得注意的是,出于测试目的,我将PSDrive删除留在了那里,因为如果脚本没有完成,并且您在进行更改后尝试再次运行它,您将得到一个错误。

代码语言:javascript
复制
#Ensure previous PSDrive 'p' is removed
Remove-PSDrive P
#Creates new PSDrive
New-PSDrive -Name P -PSProvider FileSystem -Root \\YOURSERVERNAMEHERE\YOURFILEPATHHERE
#Login to server
new-object -typename System.Management.Automation.PSCredential -argumentlist "YOURDOMAINORSERVERUSERNAMEHERE",$password
#Copies installer files from server to the local desktop
Copy-Item -Path \\YOURSERVERNAMEHERE\YOURFILEPATHHERE\ccsetup502.exe -Destination C:\YOURFILEPATHHERE
#Executes copied installers, runs the installer silently, waits until the installer has completed
Start-Process C:\YOURFILEPATHHERE\ccsetup502.exe -ArgumentList "/S" -Wait -Verb RunAs
#Deletes leftover installer files
Remove-Item C:\YOURFILEPATHHERE\ccsetup502.exe

希望这能帮助其他被困在未来的人!

感谢任何其他贡献了自己努力的人。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28268341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档