A little background…we have a PAM (privileged access management) solution called Cyberark that rotates our admin credentials and provides a secure portal for RDP, SSH etc. I am programmatically trying to check out the password through the rest request and pass those creds into the custom PS object so I can log into O365.
$url = "https://cyberark/vault/mycredslocation" $response = Invoke-RestMethod -uri $url $password = ConvertTo-SecureString $response.content -AsPlainText -Force $cred = New-Object System.Management.Automation.PSCredential($response.UserName + "@domain.com", $password) Set-ExecutionPolicy RemoteSigned $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/?proxymethod=rps -Credential $cred -Authentication Basic -AllowRedirection Import-PSSession $Session -AllowClobber
Error message is:
New-PSSession : The WinRM client cannot process the request. Requests must include user name and password when Basic or Digest authentication mechanism is used. Add the user name and password or change the
authentication mechanism and try the request again.
At C:\Scripts\users\aim2.ps1:13 char:12
- $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne …
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidArgument: (https://outlook…proxymethod=rps:Uri) [New-PSSession], PSInvalidOperationException
- FullyQualifiedErrorId : CreateRemoteRunspaceFailed,Microsoft.PowerShell.Commands.NewPSSessionCommand
Import-PSSession : Cannot validate argument on parameter ‘Session’. The argument is null. Provide a valid value for the argument, and then try running the command again.
At C:\Scripts\users\aim2.ps1:14 char:18
- Import-PSSession $Session -AllowClobber
-
~~~~~~~~
- CategoryInfo : InvalidData: ( [Import-PSSession], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand
I have tried the different types of authentication mechanisms and still get various errors. I have verified the proper username and password are being checked out. I have also used this code to connect to other servers and it works fine.