Forum Discussion
Iteration on Powershell
Hi Folks!!
Below is the requirement which i need to implement.
This is in context to Power BI CMDLET in PowerShell.
Step :1 -> Get-PowerBIWorkspace
<This will give all the workspaces we have in our organization>
Step :2 -> Get-PowerBIDataFlow -WorkSpaceID <id of workspace>.
I need to pass WorkSpaceID retrieved in Step-1 one by one to Step-2 WorkSpaceID.
How to write PowerShell script that can do this activity, i.e. passing WorkSpaceID from step 1 to step 2 one by one and consolidate the output to one CSV file.
Please suggest!!
Thanks
Amit
7 Replies
So Get-PowerBIWorkspace will show (by default) the first 100 workspaces your user is assigned to, sso you'll probably want to get all workspaces you're assigned to by calling Get-PowerBIWorkspace -All.
I've not got any PowerBI workspaces that I can get "Get-PowerBIDataFlow" to run on but it apparently returns an object, which can be passed to ConvertTo-Csv, then pipe that to Out-File to stick it in a .csv. So hopefully something like this will do the job:
$workspaces = Get-PowerBIWorkspace -All foreach ($workspace in $workspaces) { Get-PowerBIDataFlow -Workspace $workspace | ConvertTo-Csv | Out-File -FilePath "c:\output.csv" -Append }
If not then you'll have to manipulate the data a bit - not sure what that cmdlet returns so can't say what that would be:
$workspaces = Get-PowerBIWorkspace -All foreach ($workspace in $workspaces) { $data = Get-PowerBIDataFlow -Workspace $workspace #do something with $data to get what you need into a variable called $csv $csv | Out-File -FilePath "c:\output.csv" -Append }
Edit: Second attempt... first attempt replied to the wrong post and didn't read the question properly, haha.
- amsrivas28Copper Contributor
CoasterKaty 🙂 🙂
Its works though.:)
Just a little more to ask, I want Workspace ID as well in the output file which is passed to second command.
Will this be possible.
Thanks
Amit
amsrivas28 Should be, if you can get me an example of what
Get-PowerBIDataFlow
returns (as I don't have any PowerBI with data flows set up to try it with) I'll probably be able to put some code together.
- farismalaebIron Contributor
You need to store the result of Get-PowerBIWorkSpace into variable and the use the variable in Step to
so it will be like this
$Result=Get-PowerBIWorkspace Get-PowerBIDataFlow -WorkSpaceID $Result
This should help.
and also it might depend on the output of the first line
-----
If this answer helpful, please click on best Respone