Office 365 - Connecting to Exchange using PowerShell WinRM issues - powershell

I am trying to connect to my O365 Exchange Online but getting WinRM error messages when doing so.
$user = "user#domain.co.uk"
$cred = Get-Credential -Credential $user
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" -Credential $cred -Authentication "Basic" -AllowRedirection
when running that I get the following error message:
> New-PSSession : [outlook.office365.com] Connecting to remote server
> outlook.office365.com failed with the following error message : The
> WinRM client cannot process the request. Basic authentication is
> currently disabled in the client configuration. Change the client
> configuration and try the request again. For more information, see the
> about_Remote_Troubleshooting Help topic. At line:1 char:20
> + $exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -Connecti ...
> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession],
> PSRemotingTransportException
> + FullyQualifiedErrorId : -2144108321,PSSessionOpenFailed
I have looked online around WinRM and basic authentication.
I have enabled basic authentication through GPO but this hasn't done much.
Any information would be great.
Thanks

Looks to me like you have MFA enabled for the admin account - disable that. Cheers.

Related

Failed to resolve tenant name from SMTP address [FailureCategory=Cafe-HttpProxyException]

I am trying to connect O365 exchange / Exchange Online from powershell, I am using this link as guide.
however after running this powershell command
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
I am getting below error
This is error message
New-PSSession : [outlook.office365.com] Connecting to remote server outlook.office365.com failed with the following
error message :
[ClientAccessServer=SG2PR01CA0093,BackEndServer=,RequestId=2498a60b-034b-40d1-9e57-3e04fdae8d5f,TimeStamp=4/16/2019
9:48:00 AM] [FailureCategory=Cafe-HttpProxyException] Failed to resolve tenant name from SMTP address
'anna007#nitin.onmicorosft.com'. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin
gTransportException
+ FullyQualifiedErrorId : -2144108477,PSSessionOpenFailed
It was username / password issue, I was copy-pasting the username and password and while copy-pasting it was taking space in password.
This can be caused by a lack of an Exchange subscription

Connect to Exchange server using powershell

I tried running the following script to connect to an exchange server but I get the below error. Is anything wrong with the script? Are there any changes to be done from the server end?
Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned
$LiveCred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://mail.company.tld/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Error:
New-PSSession : [mail.deloitte.ca] Connecting to remote server mail.deloitte.ca failed with the following error message : The WinRM client sent a request to an HTTP
server and got a response saying the requested HTTP URL was not available. This is usually returned by a HTTP server that does not support the WS-Management protocol.
For more information, see the about_Remote_Troubleshooting Help topic.
At line:4 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -Conne ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : URLNotAvailable,PSSessionOpenFailed
Have you checked PowerShellVirtualDirectory as mentioned in this document? It mentions exact same issue.
Assuming your ConnectionUri is correct, most likely PowerShell remoting is not enabled on the target CAS server. You can enable it by running this on the CAS server directly:
Enable-PSRemoting
You may also need to configure the PowerShell virtual directory with:
Set-PowerShellVirtualDirectory "[ServerName]\POWERSHELL (default web site)" -BasicAuthentication $true

Powershell Connect to Exchange Server failed

I would like to connect to Exchange Server 2010 by using PowerShell.
I am using the following command:
PS C:\Windows\system32> $UserCredential = Get-Credential
PS C:\Windows\system32> $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://<serverName>/powershell-liveid/ -Credential $UserCredential -Authenticat
At this point I got the following error message:
WARNING: Your connection has been redirected to the following URI: "https://****************/owa/pow
ershell-liveid "
New-PSSession : [******************] Connecting to remote server **************** failed
with the following error message : The WinRM client received an HTTP status code of 440 from the remote
WS-Management service. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:12
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession],
PSRemotingTransportException
+ FullyQualifiedErrorId : -2144108273,PSSessionOpenFailed
I have tried to search for this 440 Error and figure out what is the exact cause for this error, but got no result. Could anyone please give some ideas about why it fails and how to fix it?
On all the exchange servers that I manage the uri is http://EXCHANGESERVERfqdn/PowerShell

Using webjobs to run powershell script shows "The request is not supported" error

I'm trying to run following powershell script using webjobs, but receive an error. Local run works just fine.
$Session = New-PSSession -ConfigurationName Microsoft.Exchange `
-ConnectionUri https://outlook.office365.com/powershell-liveid/ `
-Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
The output from webjob run details is:
ERR ] New-PSSession : [outlook.office365.com] Connecting to remote server
outlook.office365.com failed with the following error message : WS-Management
cannot process the request. The operation failed because of an HTTP error. The
HTTP error (50) is: The request is not supported. . For more information, see
the about_Remote_Troubleshooting Help topic.
+ $Session = New-PSSession -ConfigurationName Microsoft.Exchange
-ConnectionUri ht ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : WinRMOperationAborted,PSSessionOpenFailed
Is it possible to connect to remote Exchange online server from azurewebsites webjob and "do something" there?

Unable to connect to live#edu through PowerShell

I am trying to connect to live#edu using PowerShell with the following command.
$SessionNew = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://pod51002psh.outlook.com/powershell
Error:
[pod51002psh.outlook.com] Connecting to remote server failed with the
following error message : The WinRM client cannot process the
request. The destination computer returned an empty response to the
request. For more information, see the about_Remote_Troubleshooting
Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [],
PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionOpenFailed
Can anyone suggest me what to do with this type of errors?
I am working with following System enviornment:
Win 7, default version of PowerShell & IIS feature enabled.
Is this Code working?
$Uri = "https://pod51002psh.outlook.com/powershell/"
$Credentials = Get-Credential
$SessionNew = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $Uri -Credential $Credentials -Authentication Basic –AllowRedirection
Import-PSSession $SessionNew
In order for Import-PSSession to work though, you will have to change local execution policy with:
Set-ExecutionPolicy remotesigned