Help Me .... powershell code is not working!

Hi,

I have a script that have to recovery some information from an API rest (from powerBI)
This is the code used
Invoke-PowerBIRestMethod -Url “https://api.powerbi.com/v1.0/myorg/groups/XX-XX-XX-XX/datasets” -Method Get |
ConvertFrom-Json |
ForEach-Object {
[PSCustomObject] @{
id = $.id;
Name = $
.name;
}
}

unfortunately the returned value are empty.
If I launch the rest api command return correctly a json with several fields, and I need from these fields only id and name.
what’s wrong with this code ?

To make it cleaner, I would probably try to break some of those pipes down.

$dataset = Invoke-PowerBIRestMethod -Url “https://api.powerbi.com/v1.0/myorg/groups/XX-XX-XX-XX/datasets” -Method Get | ConvertFrom-Json

Then do your foreach

ForEach ($data in $dataset) {
[PSCustomObject] @{
        ID = ($data).ID
        Name = ($data).Name
  }
}

If you want to keep as is, try adding the _ in your table after $, and remove the ;

ForEach-Object {
[PSCustomObject] @{
id = $_.id
Name = $_.name
}
} 

Also, welcome to the forum.
To make the code easier to read, select the </> icon on your message taskbar and paste your script in there. Comes out like it does in my reply.
Makes it easier to copy and view.