Piping an array and adding a column

Good morning,

I’ve got an array in the variable $a which contains the output from Get-AzureADDevice -all $true | select ObjectID

There are about 20 colums in the array and about 2000 rows. One of the rows contains an object ID whihc I can use to pipe to another command as follows Get-AzureADDeviceRegisteredUser -ObjectId

This Get-AzureADDeviceRegisteredUser -ObjectId returns a user.

All I get back is the user object ID and a username, however I need this information to correspond to the user ID in the initial Get-AzureADDevice.

 

How cal I append the object Id and username from the Get-AzureADDeviceRegisteredUser back into the $a variable which is the array created when I run Get-AzureADDevice

 

Is there a quick way to do this in PowerShell

 

What you see on the console and describe as column is an object property. What you describe as row is a record in a returned collection of objects.
Get-AzureADDevice -all $true returns an object of type Microsoft.Open.AzureAD.Model.Device
You can add properties to the returned object by using the Add-member cmdlet as in:

$DeviceList = Get-AzureADDevice -all $true 
$DeviceList | Add-Member -MemberType NoteProperty -Name UserDisplayName -Value '' # It already has a (device) DisplayName property
$DeviceList | Add-Member -MemberType NoteProperty -Name UserPrincipalName -Value ''

foreach ($Device in $DeviceList) {
    $DeviceRegisteredUser = Get-AzureADDeviceRegisteredUser -ObjectId $Device.ObjectId
    $Device.UserDisplayName   = $DeviceRegisteredUser.DisplayName
    $Device.UserPrincipalName = $DeviceRegisteredUser.UserPrincipalName    
}

$DeviceList | FT DeviceId,DisplayName,DeviceOSType,DeviceOSVersion,UserDisplayName,UserPrincipalName -a 

Thanks Sam, this is great. I added the following to add the items to the array and it works well - so thanks

$DeviceList = Get-AzureADDevice -all $true | select *
$DeviceList | Add-Member -MemberType NoteProperty -Name UserDisplayName -Value ‘’ # It already has a (device) DisplayName property
$DeviceList | Add-Member -MemberType NoteProperty -Name UserPrincipalName -Value ‘’
foreach ($Device in $DeviceList) {

$DeviceRegisteredUser = Get-AzureADDeviceRegisteredUser -ObjectId $Device.ObjectId
$Device.UserDisplayName = $DeviceRegisteredUser.DisplayName
$Device.UserPrincipalName = $DeviceRegisteredUser.UserPrincipalName
write-host $DeviceRegisteredUser.UserPrincipalName
$devicelist += $DeviceRegisteredUser.DisplayName
$devicelist += $DeviceRegisteredUser.UserPrincipalName
}
$DeviceList | FT DeviceId,DisplayName,DeviceOSType,DeviceOSVersion,UserDisplayName,UserPrincipalName -a