Displaying information from two sources

I want to display current Citrix-sessions and the following AD-information for the users:

Name (From AD), streetAddress (From AD), physicalDeliveryOfficeName (From AD), DeviceId (From Citrix), LaunchedViaHostName (From Citrix)

These lines get me the Citrix session information I need:

------

Asnp Citrix.*
Import-Module ActiveDirectory
$users = Get-BrokerSession |select -uniq UserUPN, DeviceId, LaunchedViaHostName

-----

After those commands I have the following information in an array $users:

Because I now have the UserUPN information available, I should be able to map it to AD accounts to get more information. I try to get the information displayed with these commands:


foreach ($i in $users) {

Get-ADUser -LDAPFilter "(userprincipalname=$i.UserUPN)" -properties physicalDeliveryOfficeName, streetAddress | select name, streetAddress, physicalDeliveryOfficeName, $i.DeviceId, $i.LaunchedViaHostName |sort-object physicalDeliveryOfficeName

}

But Ill get an error:

select : The value of a parameter was null; one of the following types was expected: {System.String, System.Management.

Automation.ScriptBlock}.

At line:2 char:113

+ Get-ADUser -LDAPFilter "(userprincipalname=$i.UserUPN)" -properties physicalDeli ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidArgument: (:) [Select-Object], NotSupportedException

    + FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand

If I use this command, it works, but then I cannot display DeviceId and LaunchedViaHostName information:
$users.userupn | %{ Get-ADUser -LDAPFilter "(userprincipalname=$_)" -properties physicalDeliveryOfficeName, streetAddress} | select name, streetAddress, physicalDeliveryOfficeName |sort-object physicalDeliveryOfficeName


  • Edited by hafka 1 hour 48 minutes ago
February 12th, 2015 4:43am

Something like this should work I think, I don't use Citrix so I cannot test it unfortunately.

$users | % {
$devid = $_.DeviceId
$hostn = $_.LaunchedViaHostName
$upn = $_.UserPrincipalName
 
 Get-ADUser -LDAPFilter "(userprincipalname=$Upn)" -properties physicalDeliveryOfficeName, streetAddress | select name, streetAddress, physicalDeliveryOfficeName, @{N="DeviD";E={$devid}},@{N="Hostname";E={$hostn}} |sort-object physicalDeliveryOfficeName}

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 4:59am

Braham20: Unfortunately I get this error message:

Get-ADUser : The search filter cannot be recognized
At line:5 char:2
+  Get-ADUser -LDAPFilter "(userprincipalname=$Upn)" -properties physicalDeliveryO ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser


  • Edited by hafka 1 hour 17 minutes ago
February 12th, 2015 5:14am

Sorry, give this a try, I got my names mixed up - 

$users | % {
$devid = $_.DeviceId
$hostn = $_.LaunchedViaHostName
$upn = $_.UserUPN
 
 Get-ADUser -LDAPFilter "(userprincipalname=$Upn)" -properties physicalDeliveryOfficeName, streetAddress | select name, streetAddress, physicalDeliveryOfficeName, @{N="DeviD";E={$devid}},@{N="Hostname";E={$hostn}} |sort-object physicalDeliveryOfficeName}


  • Edited by Braham20 42 minutes ago
  • Marked as answer by hafka 11 minutes ago
Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 5:49am

For your title the sample code is below

$bios = Get-WmiObject -Class Win32_BIOS
$os = Get-WmiObject -Class Win32_OperatingSystem
$property =  @{
"BIOS Serial" = $bios.SerialNumber
"OS" = $os.Caption

}

$object = New-Object -TypeName PSObject -Property $property

$object
February 12th, 2015 5:57am

In your code change this

foreach ($i in $users.UserUPN) {

Get-ADUser -LDAPFilter "(userprincipalname=$i)" -properties physicalDeliveryOfficeName, streetAddress | select name, streetAddress, physicalDeliveryOfficeName, $i.DeviceId, $i.LaunchedViaHostName |sort-object physicalDeliveryOfficeName

}
Import-Module ActiveDirectory
$users = Get-BrokerSession |select -uniq UserUPN, DeviceId, LaunchedViaHostName

foreach ($i in $users.UserUPN) {

Get-ADUser -LDAPFilter "(userprincipalname=$i)" -properties physicalDeliveryOfficeName, streetAddress | select name, streetAddress, physicalDeliveryOfficeName, $i.DeviceId, $i.LaunchedViaHostName |sort-object physicalDeliveryOfficeName

}

Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 6:05am

Hi Chen V,

I get this error:

Get-ADUser : The search filter cannot be recognized
At line:2 char:1
+ Get-ADUser -LDAPFilter "(userprincipalname=$i)" -properties physicalDeliveryOffi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser

February 12th, 2015 6:11am

Yes because I made typo - Corrected in below code

Import-Module ActiveDirectory
$users = Get-BrokerSession |select -uniq UserUPN, DeviceId, LaunchedViaHostName
foreach ($i in $users.UserUPN) {

Get-ADUser -LDAPFilter "(userprincipalname=$i)" -properties physicalDeliveryOfficeName, streetAddress | select name, streetAddress, physicalDeliveryOfficeName, $i.DeviceId, $i.LaunchedViaHostName |sort-object physicalDeliveryOfficeName

}
Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 6:12am

Thanks, this works.
February 12th, 2015 6:21am

And this was also good information
Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 6:22am

Cheers! Glad it worked!
February 12th, 2015 6:23am

One more question about the formatting:

By default powershell seems to change the output format from table to list if five or more properties are displayed.

If I add "| ft" to the end of the command the results are displayed as a table, but it causes column headers to appear multiple times:

How could I make sure that column headers appear only once?


  • Edited by hafka 3 minutes ago
Free Windows Admin Tool Kit Click here and download it now
February 12th, 2015 6:28am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics