开发者

How to deny Windows Credential Password Prompt everytime when operate remote windows service in powershell?

Below is my code:开发者_Python百科

$s = Get-WmiObject -computer 10.10.zz.zz Win32_Service -Filter "Name='XXX'" -credential (Get-Credential XXXXXX\fanwx)
$s.stopservice()
copy-item D:\.....\aaa.exe -destination \\10.10.zz.zz\c$\vvv\
copy-item D:\.....\aaa.pdb -destination \\10.10.zz.zz\c$\vvv\

$s.startservice()

everytime executed, will be prompted enter the password of the remote server. Is there a way allowed me only enter once in powershell OR read the credential in Credential Manager?

Thanks.


Just start by

$cred = Get-Credential "XXXXXX\fanwx"

and after :

$s = Get-WmiObject -computer 10.10.zz.zz Win32_Service -Filter "Name='XXX'" -credential $cred

You can put the password on the disk :

PS > $cred.Password | ConvertFrom-SecureString | Set-Content c:\temp\password.txt

And retreive it with :

$password = Get-Content c:\temp\password.txt | ConvertTo-SecureString
$cred = New-Object System.Management.Automation.PsCredential "UserName",$password
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜