Hashtable usage mid-function

Welcome Forums General PowerShell Q&A Hashtable usage mid-function

Viewing 0 reply threads
  • Author
    Posts
    • #5243
      Participant
      Topics: 1562
      Replies: 0
      Points: 0
      Rank: Member

      by figueroa2david at 2012-10-29 15:42:58

      I have a v2 script that I use with Citrix XenDesktop to email a daily report to the admin team. After taking Don’s awesome Powershell masterclass, I am working on some improvements to it, but I am running into a snag..

      The key function here is:
      $message.Body = Get-BrokerDesktop -Filter {SessionState -eq "Disconnected" -or SessionState -eq "Unknown"} |
      Select-Object -Property SessionUserName,
      @{name='DisplayName';expression={Get-ADUser -Identity (Split-Path -Path $_.SessionUserName -Leaf) |
      Select-Object -Property Name}},
      SessionState,
      ClientName,
      HostedMachineName,
      SessionStateChangeTime | ConvertTo-Html

      The key here is XD is putting out an object type of Citrix.Broker.Admin.SDK.Desktop, and the SessionUserName is a MemberType of NoteProperty. I am using the split function to extract the user name, and using that to look up the user’s display name to put into the table. (Eventually, I will convert this into a full blown function.. but baby steps 🙂

      The issue I am getting is the output – it comes out like this: (private data is sanitized, and shown here in <> symbols and the email columns *do* line up properly)

      SessionUserName DisplayName SessionState ClientName HostedMachineName SessionStateChangeTime
      <domain\username> @{Name=<displayname>} Disconnected <clientname> <XD Machine Name> 10/29/2012 4:31:23 PM

      In the output, the actual strings ‘@{name=’ and ‘}’ are actually printing in the body along with the correct displayname? Hopefully this is just something small that I overlooked without realizing it.

      Thanks,

      David F.

      by DonJ at 2012-10-30 07:51:37

      Use -ExpandProperty with Select-Object, instead of -Property.

Viewing 0 reply threads
  • The topic ‘Hashtable usage mid-function’ is closed to new replies.