powershell创建密文密码文件

$File = "\\10.10.10.1\test\Password.txt"
[Byte[]] $key = (1..16)
$Password = "123456" | ConvertTo-SecureString -AsPlainText -Force
$Password | ConvertFrom-SecureString -key $key | Out-File $File

 

 $a=Read-Host "请输入要修改的计算机名"
 $File = "\\10.10.10.1\test\Password.txt“
 [Byte[]] $key = (1..16)
 $encpasswd = Get-Content $File
 $ss = ConvertTo-SecureString -String $encpasswd -Key $key
 $cred = New-Object System.Management.Automation.PSCredential 'test.cn\zhangsan', $ss
 Add-Computer -ComputerName $a -DomainName test.cn -Credential $cred


 #加域
Add-Computer -ComputerName Server01 -LocalCredential Server01\Admin01 -DomainName Domain02 -Credential Domain02\Admin02 -Restart -Force
#退域
Remove-Computer -UnjoinDomaincredential Domain01\Admin01 -Passthru -Verbose -Restart

 

 

https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-1/

posted @ 2020-09-24 11:29  会飞的老虎  阅读(280)  评论(0)    收藏  举报