I am trying to build a script that installs an application with encrypted local admin credentials on the pc when the user logged in is not an admin.
I am running the below cmdlet:
$User = "admin@domain.com" $PasswordFile = "C:\temp\Cred\Password.txt" $KeyFile = "C:\temp\Cred\AES.key" $key = Get-Content $KeyFile $MyCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key) Start-Process -FilePath C:\Temp\7z2301-x64.exe -Credential $MyCredential
However, I am getting below error even though I am passing correct credentials:
Start-Process : This command cannot be run due to the error: The user name or password is incorrect.At line:13 char:1+ Start-Process -FilePath C:\Temp\7z2301-x64.exe -Credential $MyCredent ...+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOp erationException+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.C ommands.StartProcessCommand
Can someone please help on this?
Thank you in advance!
Getting error invalid username and password when running above code.