Most of time facing Access denied issue for Exchange server - powershell

I am trying to establish a PowerShell session to run several Exchange commands on an Exchange server on the localhost. This is not a constant issue, script is running successfully for sometime, but most of the time it is throwing following error:
New-PSSession : [Exchange-server-name] Connecting to remote server Exchange-server-name failed with the following error message : Access is denied. For more
information, see the about_Remote_Troubleshooting Help topic.
At line:9 char:15
+ $newsession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ...
+
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionOpenFailed
Import-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Supply a non-null argument and try the command again.
At line:10 char:27
+ import-PSSession -session $newsession -AllowClobber
Following is my PSSession command:
$newsession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://Exchange-server-name/PowerShell/ -Authentication Kerberos -Credential $Credential

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

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?

connecting from powershell 2.0 to local exchange 2007

I'm trying to connect from my PowerShell to Exchange 2007 (both are on the same computer).
What am I missing?
My code:
Set-ExecutionPolicy RemoteSigned
$cred = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
https://localhost/powershell/ -Credential $cred -Authentication Basic –AllowRedirection
Import-PSSession $Session
The error I get:
[localhost] Connecting to remote server failed with the following error message : The server certificate on the destination computer (localhost:443) has the following errors:
The SSL certificate is expired. For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionOpenFailed
Import-PSSession : Cannot validate argument on parameter 'Session'. The argument is null. Supply a non-null argument and try the command again.
At line:3 char:17
+ Import-PSSession <<<< $Session
+ CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.ImportPSSessionCommand
Remoting does not work with Exchange 2007. Never has.

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