Share via

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 | Exchange Server | Management
Exchange | Exchange Server | Management

The administration and maintenance of Microsoft Exchange Server to ensure secure, reliable, and efficient email and collaboration services across an organization.

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments

Answer accepted by question author
  1. Rich Matheisen 48,116 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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.