"translate results"

Hi there
I have a script that goes after certain values of attributes in azure
most of attributes are straight forward so like true/false id name
one of them is not the “real” value so it returns 0,1,2,3,4,5 which translate to their real values created manually somewhere like company1 company2 company3…
the return values in table will look like this:

deviceName deviceEnrollmentType ownerType TagIds


WIN10GPO windowsCoManagement company {1}
WIN10OFFICE userEnrollment company {0}

is there away I could show the ‘tagids’ as their real values?
Thanks

turbo,
Welcome to the forums.

Usually curly braces indicate an array instead of a simple value. But without you sharing your code it’ll be hard to recommend something meaningful. You could try to use a

Select-Object -ExpandProperty TagIds

to expand the array.

Thanks
Yes this attribute can represent more than one value(in my case there will only be one value and that’s what i am after)
i thought of maybe using switch with values translation

I don’t get that. How about sharing your actual code?

1 Like

i ended up doing something like this:
$Results += [PSCustomObject] @{
Devicename = $d.devicename
DeviceEnrollmentType = $d.deviceEnrollmentType
Ownertype = $d.ownertype
DeviceCategoryDisplayName=$d.deviceCategoryDisplayName
UserPrincipalName =$d.userPrincipalName
EmailAddress=$d.emailAddress
Id=$d.id
Userid=$d.userId
Operatingsystem=$d.operatingSystem
Manageddevicename=$d.managedDeviceName
RoleScopeTagIds=switch ($d.roleScopeTagIds){
0 {“default”}
1 {“realvalue1”}
2 {“realvalue2”}

}

I assume your question is answered, right? :wink:

Please format your code as code next time. It will look like this when you do:

[PSCustomObject] @{
    Devicename                = $d.devicename
    DeviceEnrollmentType      = $d.deviceEnrollmentType
    Ownertype                 = $d.ownertype
    DeviceCategoryDisplayName = $d.deviceCategoryDisplayName
    UserPrincipalName         = $d.userPrincipalName
    EmailAddress              = $d.emailAddress
    Id                        = $d.id
    Userid                    = $d.userId
    Operatingsystem           = $d.operatingSystem
    Manageddevicename         = $d.managedDeviceName
    RoleScopeTagIds           = switch ($d.roleScopeTagIds) {
        0 { 'default' }
        1 { 'realvalue1' }
        2 { 'realvalue2' }
    }
}

Isn’t that much easier to read? :wink:

2 Likes

Much, much easier. And it’s easy to do!

1 Like

To answer your question, it’s an array, so you need to process it with a for loop to convert each tag in the array to the real value. Also, using += is not an efficient way to build objects, just put a variable in front of the loop and everything that is returned rolls up to that variable:

$results = foreach ($d in $devices) {
    [PSCustomObject] @{
        Devicename                = $d.devicename
        DeviceEnrollmentType      = $d.deviceEnrollmentType
        Ownertype                 = $d.ownertype
        DeviceCategoryDisplayName = $d.deviceCategoryDisplayName
        UserPrincipalName         = $d.userPrincipalName
        EmailAddress              = $d.emailAddress
        Id                        = $d.id
        Userid                    = $d.userId
        Operatingsystem           = $d.operatingSystem
        Manageddevicename         = $d.managedDeviceName
        RoleScopeTagIds           = foreach ($tag in $d.roleScopeTagIds) {
            switch ($tag) {
                0 { 'default' }
                1 { 'realvalue1' }
                2 { 'realvalue2' }
            }
        }
    }
}
2 Likes