I'm writing a script to automate my server builds. part of the script is changing the local administrator password. I'm trying to save the password as a secure string into a txt file and then after a few reboots I will invoke that password to change the local administrator password. This is what I have but it's not working. If I just type a random password in, it works, but when pulling in a secure string from a txt file it is failing
So first I set the password like this
read-host -assecurestring | convertfrom-securestring -Key (1..16) | out-file c:\admin.txt
Then on a later script I do
$adminpass = gc C:\admin.txt | ConvertTo-SecureString -Key (1..16)
$strcomputer = "."
$admin=[adsi]("WinNT://" + $strcomputer + "/username,user")
$admin.psbase.invoke("SetPassword","$adminpass")
Thanks