Reputation: 25
I am trying to run this ps command within a python script :
subprocess.call('powershell.exe $username = "[email protected]";$password = Get-Content "C:/Scripts/user.txt" | ConvertTo-SecureString;$cred = new-object -typename System.Management.Automation.PSCredential ` -argumentlist $username, $password;Connect-MsolService -Credential $cred;Get-MsolUser -UserPrincipalName user@example, shell=TRUE)
So basically as you can understand I call this command within the script and autologin in azure and get the user. My problem is that I am getting this error :
'ConvertTo-SecureString' is not recognized as an internal or external command, operable program or batch file.
Any ideas? Thank you so much in advance everybody.
Upvotes: 0
Views: 429
Reputation: 4644
You should run this as it was a normal CMD line. Use CMD's escape symbol ^
before special chars.
Example:
powershell.exe -Command Get-ChildItem ^| ConvertTo-Json
In difficult cases it's easier to use powershell.exe -EncodedCommand ENCCMD
where ENCCMD
is Base64-encoded text.
Avoid using MSOL Powershell CmdLets, use Microsoft Graph Api /users natively in python.
Upvotes: 0