rpribanic
asked on
problem running exchange powershell script
I have 8 exchange servers in environment out of which 4 are in site A and 4 are in site B. I'm using scripts to monitor various health variables for all of these. All was working fine for me for 2 months until this Tuesday. Suddenly all servers in site B are failing to run script remotely.
I did some troubleshooting and came to find out that if I remote into any server that is giving me trouble and start windows powershell than load Add-PSSnapin Microsoft.Exchange.Managem ent.PowerS hell.e2010 non of the exchange commandlets want to run. Error I get is
Get-MailboxDatabaseCopySta tus : Value cannot be null.
Parameter name: serverSettings
At line:1 char:30
+ Get-MailboxDatabaseCopySta tus <<<<
+ CategoryInfo : NotSpecified: (:) [Get-MailboxDatabaseCopySt atus], ArgumentNullException
+ FullyQualifiedErrorId : System.ArgumentNullExcepti on,Microso ft.Exchang e.Manageme nt.SystemC onfigurati onTasks.Ge tM
ailboxDatabaseCopyStatus
If I run exchange commandlet from EMC it works fine.
This is script I'm running from remote machine that started failing with similar error as above:
error I get on remote machine is:
Get-MailboxDatabaseCopySta tus : Value cannot be null.
Parameter name: serverSettings
At C:\Program Files\NSClient++\scripts\c ontentinde xstate.ps1 :48 char:48
+ ForEach ($Type in Get-MailboxDatabaseCopySta tus <<<< -Server em-dr-exmb01)
+ CategoryInfo : NotSpecified: (:) [Get-MailboxDatabaseCopySt atus
], ArgumentNullException
+ FullyQualifiedErrorId : System.ArgumentNullExcepti on,Microso ft.Exchang e.
Management.SystemConfigura tionTasks. GetMailbox DatabaseCo pyStatus
OK: All content index states are healthy!
I did some troubleshooting and came to find out that if I remote into any server that is giving me trouble and start windows powershell than load Add-PSSnapin Microsoft.Exchange.Managem
Get-MailboxDatabaseCopySta
Parameter name: serverSettings
At line:1 char:30
+ Get-MailboxDatabaseCopySta
+ CategoryInfo : NotSpecified: (:) [Get-MailboxDatabaseCopySt
+ FullyQualifiedErrorId : System.ArgumentNullExcepti
ailboxDatabaseCopyStatus
If I run exchange commandlet from EMC it works fine.
This is script I'm running from remote machine that started failing with similar error as above:
if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) -eq $null)
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
}
$NagiosStatus = "0"
$NagiosDescription = ""
ForEach ($Type in Get-MailboxDatabaseCopyStatus -Server em-dr-exmb01)
{
if ($Type.ContentIndexState -notlike "*Healthy*")
{
# Look for failed Index state
if ($NagiosDescription -ne "")
{
# Format the output for Nagios
$NagiosDescription = $NagiosDescription + ", "
}
$NagiosDescription = $NagiosDescription + $Type.Name + " = " + $Type.ContentIndexState
# Set the status to failed.
$NagiosStatus = "2"
}
}
# Output, which string should we write to Nagios?
if ($NagiosStatus -eq "2")
{
Write-Host "CRITICAL:"$NagiosDescription
}
else
{
Write-Host "OK: All content index states are healthy!"
}
exit $NagiosStatus
error I get on remote machine is:
Get-MailboxDatabaseCopySta
Parameter name: serverSettings
At C:\Program Files\NSClient++\scripts\c
+ ForEach ($Type in Get-MailboxDatabaseCopySta
+ CategoryInfo : NotSpecified: (:) [Get-MailboxDatabaseCopySt
], ArgumentNullException
+ FullyQualifiedErrorId : System.ArgumentNullExcepti
Management.SystemConfigura
OK: All content index states are healthy!
any patching done recently?
ASKER
no. that is first thing I was looking at. also to my knowledge nothing was changed on those 4 servers that are throwing errors.
Change this:
ForEach ($Type in Get-MailboxDatabaseCopySta tus -Server em-dr-exmb01)
to this
$status = get-mailboxdatabasecopysta tus -Server em-dr-exmb01
foreach ($type in $status)
also run get-mailboxdatabasecopysta tus -server em-dr-exmb01 to make sure it returns data. The error your getting basically says that you are passing null data.
ForEach ($Type in Get-MailboxDatabaseCopySta
to this
$status = get-mailboxdatabasecopysta
foreach ($type in $status)
also run get-mailboxdatabasecopysta
Change line 9 to
ForEach ($Type in (Get-MailboxDatabaseCopySt atus -Server em-dr-exmb01))
{
ForEach ($Type in (Get-MailboxDatabaseCopySt
{
ASKER
I just tried but no luck.
Please note that if I open local windows powershell window and add exchange powershell snapin I get the same error. After exchange snapin is loaded I can tab through all exchange commandlets but it always returns "value cannot be null".
Being that this is happening on all server in site B I am thinking it could be something related to DC authentication but cannot find anything wrong so far.
Please note that if I open local windows powershell window and add exchange powershell snapin I get the same error. After exchange snapin is loaded I can tab through all exchange commandlets but it always returns "value cannot be null".
Being that this is happening on all server in site B I am thinking it could be something related to DC authentication but cannot find anything wrong so far.
ASKER
@Sedgwick
Tried that as well and same result. I tend to think there is nothing wrong with script as it works on all servers in my A site and until 2 days ago it worked just fine on servers in B site where this issue came up now.
Tried that as well and same result. I tend to think there is nothing wrong with script as it works on all servers in my A site and until 2 days ago it worked just fine on servers in B site where this issue came up now.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@qlemo
thanks for the input I tried using import-possession before with a little different syntax but with no luck. I get different error when using import possession.
I used your example and following is the error I get on my monitoring server
[em-dr-exmb01] Processing data from remote server failed with the following err
or message: The user "domain.domain.net/Compute rs/EM-DR-E XMB02" isn't assigned
to any management roles. For more information, see the about_Remote_Troubleshoo
ting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....Remote Runspace:R e
moteRunspace) [], PSRemotingTransportExcepti on
+ FullyQualifiedErrorId : PSSessionOpenFailed
Import-PSSession : Cannot validate argument on parameter 'Session'. The argumen
t is null. Supply a non-null argument and try the command again.
At C:\Program Files\NSClient++\scripts\c ontentinde xstate.ps1 :37 char:18
+ Import-PSSession <<<< (New-PSSession -ConfigurationName Microsoft.Exchange
-ConnectionUri http://em-dr-exmb01/PowerShell/ -Authentication Kerberos)
+ CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBi
ndingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidatio nError,Mic rosoft.Pow er
Shell.Co
This is how changed script looks like after I used your example:
thanks for the input I tried using import-possession before with a little different syntax but with no luck. I get different error when using import possession.
I used your example and following is the error I get on my monitoring server
[em-dr-exmb01] Processing data from remote server failed with the following err
or message: The user "domain.domain.net/Compute
to any management roles. For more information, see the about_Remote_Troubleshoo
ting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....Remote
moteRunspace) [], PSRemotingTransportExcepti
+ FullyQualifiedErrorId : PSSessionOpenFailed
Import-PSSession : Cannot validate argument on parameter 'Session'. The argumen
t is null. Supply a non-null argument and try the command again.
At C:\Program Files\NSClient++\scripts\c
+ Import-PSSession <<<< (New-PSSession -ConfigurationName Microsoft.Exchange
-ConnectionUri http://em-dr-exmb01/PowerShell/ -Authentication Kerberos)
+ CategoryInfo : InvalidData: (:) [Import-PSSession], ParameterBi
ndingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidatio
Shell.Co
This is how changed script looks like after I used your example:
Import-PSSession (New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://em-dr-exmb01/PowerShell/ -Authentication Kerberos)
# if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) -eq $null)
# {
# Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
# }
$NagiosStatus = "0"
$NagiosDescription = ""
ForEach ($Type in (get-mailboxdatabasecopystatus -Server em-dr-exmb01))
{
if ($Type.ContentIndexState -notlike "*Healthy*")
{
# Look for failed Index state
if ($NagiosDescription -ne "")
{
# Format the output for Nagios
$NagiosDescription = $NagiosDescription + ", "
}
$NagiosDescription = $NagiosDescription + $Type.Name + " = " + $Type.ContentIndexState
# Set the status to failed.
$NagiosStatus = "2"
}
}
# Output, which string should we write to Nagios?
if ($NagiosStatus -eq "2")
{
Write-Host "CRITICAL:"$NagiosDescription
}
else
{
Write-Host "OK: All content index states are healthy!"
}
exit $NagiosStatus
ASKER
I should also mention that if I run your import-pssession from vanilla windows PowerShell it works just fine. However, when I invoke it in script it fails with above mentioned error. Also not sure if it matters but I'm calling script from Linux box that has no domain authentication. It basically communicates to server via installed agent on that particular server.
Linux box??????????????????????? ?????????? ?????????? ???Great!! !
I don't think MS supports or create PS for linux yet.
I don't think MS supports or create PS for linux yet.
ASKER
Linux uses agent on windows that is running as a service. As I mentioned before this was working just fine using Add-PSSnapin Microsoft.Exchange.Managem ent.PowerS hell.E2010
not sure if import-pssession would be option to use in my case-scenario.
not sure if import-pssession would be option to use in my case-scenario.
Did you have remote PS enable.
ASKER
ok just found fix how to runn script using import-pssession instead of Add-PSSnapin Microsoft.Exchange.Managem ent.PowerS hell.E2010
My agent service was running as local system. As soon as I changed it to run as domain username with exchange rights it executed fine on my Linux box.
Will do some more testing before deciding if this will work for my purposes.
I'm still curious to why is my initial script failing when using Add-PSSnapin Microsoft.Exchange.Managem ent.PowerS hell.E2010 . I hope I do not have issues within my AD in site B.
My agent service was running as local system. As soon as I changed it to run as domain username with exchange rights it executed fine on my Linux box.
Will do some more testing before deciding if this will work for my purposes.
I'm still curious to why is my initial script failing when using Add-PSSnapin Microsoft.Exchange.Managem
ASKER
So as I mentioned in earlier post I got it working. So to summarize I was able to get it working with code snippet provided by qlemo. I still had to add/change some parameters in order to have it working properly for my purposes.
code provided by qlemo:
Code I used:
$env:ComputerName - changed servername to variable so that it is more general and I can use same code without changing it on multiple servers
CommandName Get-MailboxDatabaseCopySta tus - added this in order to avoid warning that was returned due to unapproved verbs. This way I only load commandlet I need.
out-null - used this so that I do not get any other return on import-pssession so I can parse only return I'm interested in after running desired commandlet
Also I had to change the way I was running service so that it runs under domain username instead localsystem.
I'm still at loss why my original way of running this script started failing. If anyone has any idea of what cause to that could be I would much appreciate any suggestions.
code provided by qlemo:
Import-PSSession (New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://em-dr-exmb01/PowerShell/ -Authentication Kerberos)
Code I used:
Import-PSSession (New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$env:ComputerName/PowerShell/ -Authentication Kerberos) -CommandName Get-MailboxDatabaseCopyStatus | out-null
$env:ComputerName - changed servername to variable so that it is more general and I can use same code without changing it on multiple servers
CommandName Get-MailboxDatabaseCopySta
out-null - used this so that I do not get any other return on import-pssession so I can parse only return I'm interested in after running desired commandlet
Also I had to change the way I was running service so that it runs under domain username instead localsystem.
I'm still at loss why my original way of running this script started failing. If anyone has any idea of what cause to that could be I would much appreciate any suggestions.
ASKER
For anyone with similar issue I just wanted to update the cause to this issue. As I initially suspected there was some authentication issues with AD. One of our DC's in this particular site was acting up and we were not able to see this during initial troubleshooting. As soon as we rectified problem with DC my script started working as originally implemented.