[英]How to deny Windows Credential Password Prompt everytime when operate remote windows service in powershell?
Below is my code: 以下是我的代码:
$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() $ 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?
有没有办法允许我只在powershell中输入一次或在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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.