简体   繁体   中英

Create PSCredential from AzureAD User

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?

With Start-Process you must specify username in format "DOMAIN\\user\u0026quot;. I am not sure where from this limitation is coming.

在此处输入图片说明

Is the domain that the azure ad user account you are trying to run the command as accessible to the domain that your machine is connected to? Without more information, I can only speculate that powershell is throwing the error because it does not recognize the user or the domain the user is a member of.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM