Powershell adding @{ } to the output

I am writint va code, which will fetch all the ids from GET-GOP, to feed it to GetGPPermission to extract all details. Though I am able to get all the Ids from GPO, not able to feed them to GPPermission. Below is my code

$GPOIDs = GET-GPO -ALL | SELECT id
$results = foreach ($GPOID in $GPOIDS) {Get-GPPermission -GUID $GPOID -ALL}

GET-GPO-ALL gets all ids, however the output looks like the below

@{Id=31b2f340-016d-11d2-945f-00c04fb984f9} @{Id=6ac1786c-016f-11d2-945f-00c04fb984f9} @{Id=eb996917-09f6-46f0-9f5c-0c6d40f10e1f} @{Id=b9e5f37f-48a5-43f9-9e66-eb9014118d6f} @{Id=21313288-2189-4e4a-a1…

when each of the above is passed to Get-GPPermission, I get the below message in each input

Get-GPPermission : Cannot bind parameter ‘Guid’. Cannot convert the “@{Id=31b2f340-016d-11d2-945f-00c04fb984f9}” value
of type “Selected.Microsoft.GroupPolicy.Gpo” to type “System.Guid”.

I think Get-GPPermission is not able find the details since the @{id= and the other } at the end of the string also provided as GUID.

Can any one help, what mistake I am making and how to avoid it.

thanks

Bala,
Welcome to the forum. :wave:t3:

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in PowerShell.org 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

Instead of …

You do …

$GPOIDs = GET-GPO -ALL | Select-Object -ExpandProperty Id
$results = foreach ($GPOID in $GPOIDS) {Get-GPPermission -GUID $GPOID -ALL}

or …

$GPOIDs = GET-GPO -ALL | Select-Object -Property Id
$results = foreach ($GPOID in $GPOIDS.Id) {Get-GPPermission -GUID $GPOID -ALL}

or …

$GPOIDs = GET-GPO -ALL | Select-Object -Property Id
$results = foreach ($GPOID in $GPOIDS) {Get-GPPermission -GUID $GPOID.Id -ALL}

or just …

$results = GET-GPO -ALL | Get-GPPermission -ALL

:man_shrugging:t3:

1 Like