$File = "\10.10.10.1 estPassword.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 estPassword.txt“
[Byte[]] $key = (1..16)
$encpasswd = Get-Content $File
$ss = ConvertTo-SecureString -String $encpasswd -Key $key
$cred = New-Object System.Management.Automation.PSCredential 'test.cnzhangsan', $ss
Add-Computer -ComputerName $a -DomainName test.cn -Credential $cred
#加域
Add-Computer -ComputerName Server01 -LocalCredential Server01Admin01 -DomainName Domain02 -Credential Domain02Admin02 -Restart -Force
#退域
Remove-Computer -UnjoinDomaincredential Domain01Admin01 -Passthru -Verbose -Restart
https://www.pdq.com/blog/secure-password-with-powershell-encrypting-credentials-part-1/