I don't know why I can't figure this out, this can't be as hard as I'm making it. I'm trying to create a powershell script that will elevate itself using explicit credentials from AzureAD. I create a PSCredential object with:
$ss = ConvertTo-SecureString "p@ssw0rd" -AsPlainText -Force
$cred = New-Object PSCredential -ArgumentList 'username@domain.com', $ss
Start-Process PowerShell -Credential $cred "-NoProfile -ExecutionPolicy Bypass -Command `"cd '$pwd'; & '$PSCommandPath';`""
exit;
When I execute this I get Start-Process : This command cannot be run due to the error: The user name or password is incorrect.
I know the username and password are correct but I am guessing that it has to do with the fact that this is an AzureAD user? Do I have to format the AzureAD username differently? I've tried reformatting it every way I can think of. I've tried using Connect-AzureAD
and using Get-AzureADUser
to try to see if I could use some property of that to sign in but I'm coming up empty.
Is this even possible?