Link to home
Start Free TrialLog in
Avatar of Isaias Perez
Isaias PerezFlag for United States of America

asked on

Powershell, Encrypt Password with AES Key

I have a powershell script designed to create a local admin account. I have been trying to edit the PS script so that i dont have the password in plain text. I have created a password.txt file and a password.key file on a shared network drive open to everyone. Here is my script, i am doing something wrong. Can someone help me fix it.

Start-Transcript -Path "C:\temp\addlocaladmin.log" -NoClobber
Set-Executionpolicy -Scope CurrentUser -ExecutionPolicy UnRestricted

<#This works great but password is clear text
$Password = ""
$secureStringPassword = ($Password | ConvertTo-SecureString -AsPlainText -Force)#>

$password = Get-Content \\FILE1\$3ncrypted\password.txt | ConvertTo-SecureString -Key (Get-Content \\FILE1\$3ncrypted\password.key)
$credential = New-Object System.Management.Automation.PsCredential("TP-Admin",$password)
New-LocalUser "TP-Admin" -Password $password -FullName "TP-Admin" -Description "Local Admin Account for Intune Managed Devices"
Add-LocalGroupMember -Group "Administrators" -Member "TP-Admin"
Stop-Transcript 

Open in new window


Can someone tell me what i am doing wrong and how to fix the code?

I am getting this error message. I verified i have access to the UNC path.

User generated image
https://www.altaro.com/msp-dojo/encrypt-password-powershell/
ASKER CERTIFIED SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial