$Currentpath=Split-Path -parent $MyInvocation.MyCommand.Definition #获取脚本目录
$KeyFile = "$($Currentpath)\AES.key"
$Key = New-Object Byte[] 16 #You can use 16, 24, or 32 for AES
[Security.Cryptography.RNGCryptoServiceProvider]::Create().GetBytes($Key)
$Key | Out-File $KeyFile #将秘钥保存到"d:\AES.key"文件
$PasswordFile ="$($Currentpath)\Password.txt"
$Password = "zyf@13479961830!" | ConvertTo-SecureString -AsPlainText -Force
$Password | ConvertFrom-SecureString -Key $Key | Out-File $PasswordFile
Write-Host 加密结果 -ForegroundColor Red
Get-Content $PasswordFile
$User = "zyf\administrator"
$Key = Get-Content $KeyFile #获取秘钥
$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $Key)
Add-Computer -DomainName zyf.com -Credential $MyCredential