Command in a variable produces no output

Alexis Crawford 201 Reputation points
2021-08-09T18:16:48.563+00:00

This gives me the results that i am looking for

$ExchangeServers = Get-TransportServer

    foreach ($Server in $Exchangeservers) {

  Get-MessageTrackingLog -Server $Server.name -Start (get-date).addminutes(-1) -eventid agentinfo | select sender}

However when I put the command in a variable the results are blank. What am i doing wrong.

$ExchangeServers = Get-TransportServer

    foreach ($Server in $Exchangeservers) {

  $x= Get-MessageTrackingLog -Server $Server.name -Start (get-date).addminutes(-1) -eventid agentinfo | select sender}

$x (Results show nothing)

Thanks,
Alexis Crawford

Exchange Server Management
Exchange Server Management
Exchange Server: A family of Microsoft client/server messaging and collaboration software.Management: The act or process of organizing, handling, directing or controlling something.
7,503 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

Accepted answer
  1. Rich Matheisen 45,906 Reputation points
    2021-08-09T18:46:36.777+00:00

    Your variable "$x" is being overwritten for each server in the $ExchangeServers variable. If the last server in the array produced no output from the Get-MessageTrackingLog then $x will be empty.

    You can change "$x = Get-Mess...." to "$x += Get-Mess..." and each iteration will add its output to $x instead of overwriting $x.


0 additional answers

Sort by: Most helpful