Forum Discussion

powerbi_jenhen's avatar
powerbi_jenhen
Resolver II
4 years ago
Solved

How to return a specified dataset ID

Hi,

 

I have the below code where the source XML file has a single element for the desired dataset Name to return the ID for:

 

$DatasetName = $xmlElm.Workspace.Dataset.Default
$Dataset = Get-PowerBIDataset -WorkspaceId $Workspace.Id -Name $DatasetName
$DatasetId = $Dataset.ID
Write-Host "Dataset ID: "$DatasetId
 
The above code works if there is only one dataset in the workspace but when there's multiple datasets the $DatasetId variable contains the multiple dataset ids concatenated, I would have thought the "-Name" filter would have only returned the dataset id for this one named dataset? How can I change my code to do this?
 
Thanks. 
  • I needed to use Where-Object:

     

    $Dataset = Get-PowerBIDataset -WorkspaceId $Workspace.Id | Where-Object {$_.name -eq $DatasetName}

1 Reply

  • I needed to use Where-Object:

     

    $Dataset = Get-PowerBIDataset -WorkspaceId $Workspace.Id | Where-Object {$_.name -eq $DatasetName}