API Power BI - How to retrieve the workspace id and store it in a variable for reuse?

Hello,

How to retrieve the workspace id and store it in a variable for reuse ?

For exemple : I create a workspace with this command (New-PowerBIWorkspace -Name “ADO DEV”)

Then I want to add a user to this workspace with this command (Add-PowerBIWorkspaceUser -Id … -UserEmailAddress … -AccessRight Admin), however I need the workspace Id to add a user.

Hi, welcome to the forum :wave:

Firstly, when posting code in the forum, please can you use the preformatted text </> button. It really helps us with readability, and copying and pasting your code (we don’t have to faff about replacing curly quote marks to get things working).

How to format code on PowerShell.org

From the (not very detailed documentation) New-PowerBIWorkspace returns an object. So can you find the ID by doing this?

$workspace = New-PowerBIWorkspace -Name 'ADO DEV'
$workspace | Get-Member

If it includes the ID as part of the returned object, and assuming it’s called Id you can do this:

$workspace = New-PowerBIWorkspace -Name 'ADO DEV'
Add-PowerBIWorkspaceUser -Id $workspace.Id -UserEmailAddress ...
1 Like