Powershell – Running Get-MessageTrackingLog as a job in Powershell

exchange-2010powershell

I'm trying to create an Exchange 2010 script that will search each transport server as a job. I try the following:

$transportserver = get-transportserver
foreach ($ts in $transportserver)
{
     $ts_name = $ts.name

     $s = New-PSSession -ComputerName $ts_name
     Invoke-Command -Session $s -Script { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; Get-MessageTrackingLog -server $args[0] } -Args $ts_name
}

But I get the error:

Value cannot be null. Parameter name: serverSettings
+ CategoryInfo          : NotSpecified: (:) [Get-MessageTrackingLog], ArgumentNullException
+ FullyQualifiedErrorId : 
     System.ArgumentNullException,Microsoft.Exchange.Management.TransportLogSearchTasks.GetMessageTrackingLog

I've tried a few variations like adding more parameters but it returns the same error.

Best Answer

The script looks very simple, so i feel like your problem lays elsewhere. maybe try

invoke-command -computername $srv {Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; Get-MessageTrackingLog}

If that fails maybe walk towards another solution, with psExec fx. This is just a quick copy/paste from my personal scripts.

$ps = new-object System.Diagnostics.Process
$ps.StartInfo.Filename = "O:\pstools\psexec.exe"

Foreach ($strComputer in $Servers)
{   
    $ps.StartInfo.Arguments = " \\" 
    $ps.StartInfo.Arguments += $strComputer.Name 
    $ps.StartInfo.Arguments += " gpupdate.exe /target:computer /force"
    $ps.start()
    $ps.WaitForExit()
}