Looking for your Help with Get-AzureADdevice

Hello PS Expert,

I am looking for a direction on how I can extract the Order ID value tagged to the Autopilot device Object property ‘DevicePhysicalIds’. For example
Get-AzureADDevice -ObjectId 86d62fa8-5366-49b7-85f8-439fd7c829eb |Select-Object DevicePhysicalIds

gives me the below output

DevicePhysicalIds

{[OrderId]:Finance: HAAD Join Skip AD ping test, [ZTDID]:4d53004b-5157-4eeb-97a6-dae4019806e7, [USER-HWID]:1e3d16a7-20ba-413a-a930-a658f0c0c294:6896159468190780

Appreciate your help… Thank you!

Khogen,
Welcome to the forum. :wave:t4:

You can help us helping you when you post code, console output or error messages to format it as code here in the forum.

I don’t have access to an Azure tennant to test but my first step yould be to “drill in” the property you’re after and see how it looks. :wink: When a cmdlets outputs a list of properties instead of just one single properties you can use -ExpandProperty to enumerate this list … like this:

Get-AzureADDevice -ObjectId 86d62fa8-5366-49b7-85f8-439fd7c829eb | 
    Select-Object -ExpandProperty DevicePhysicalIds

HI All, Thank you for your response and for onboarding me to Powershell.org.
When I expand the object property I can see the values are there as a collection and I do not know ways :sob: to get only one string value … say [OrderId] from the string collection. I am attaching another screen shot with its member type… please see…


Thanks.

First of all - please stop posting pictures of code or text - that’s most of the time not helpful. If you want to share code, console output, sample data or error messages copy the text and post it here formatted as code. This way we can copy it and play with it to be able to reproduce part of your environment.

You’ve moved forward and you’re almost there … why so desparate? :wink:

$SearchPattern = [regex]::Escape('[OrderID]:Finance:')
Get-AzureADDevice -ObjectId 86d62fa8-5366-49b7-85f8-439fd7c829eb | 
    Select-Object -ExpandProperty DevicePhysicalIds |
        Where-Object {$_ -match $SearchPattern}

That should filter for the item you’re looking for.

Thank Olaf, it worked. I will keep in mind about the rules.