Forum Discussion
How to add Identity column on PowerShell Result
Hi Guys!!
I have executed below command and data has been captured.
$Workspaces = Get-PowerBIWorkspace
$Workspaces
Output is shown as below
Id : 5eyh4u7e-11e1-4c53-95f9-938fhf7d5af
Name : WorkSpace-1
IsReadOnly : False
IsOrphaned : False
IsOnDedicatedCapacity : True
CapacityId : 97jsuh6u-87hy-4k78-CF45B-C34ff354r41D
Id : b3j756b5-r745-3t56-q234-frbrf481a84f7
Name : Workspace-2
IsReadOnly : False
IsOrphaned : False
IsOnDedicatedCapacity : True
CapacityId : 97jsuh6u-87hy-4k78-CF45B-C34ff354r41D
I want to add one more column of Identity, sat ColA =1 etc as shown as below
ColA =1
Id : 5eyh4u7e-11e1-4c53-95f9-938fhf7d5af
Name : WorkSpace-1
IsReadOnly : False
IsOrphaned : False
IsOnDedicatedCapacity : True
CapacityId : 97jsuh6u-87hy-4k78-CF45B-C34ff354r41D
ColA =2
Id : b3j756b5-r745-3t56-q234-frbrf481a84f7
Name : Workspace-2
IsReadOnly : False
IsOrphaned : False
IsOnDedicatedCapacity : True
CapacityId : 97jsuh6u-87hy-4k78-CF45B-C34ff354r41D
Please suggest how to achieve this.
Thanks
Amit Srivastava
- Kevin_MorganIron Contributor
Try the below commands with Get-PowerBIWorkspace to get the required result
$result=@() $id=0 $processes = Get-Process ForEach ($process in $processes) { $id++ $result+=New-Object PsObject -Property ([ordered]@{ ColA=$id OtherColumn1=$process.Name }) }
- amsrivas28Copper Contributor
Hi Kevin_Morgan ,
I am able to add new Identity column into the Variable $Workspaces however when i tried to pass workspace into another command, it crashes, detail as below.
First Part of the PowerShell Command ; works and added new column as desired.
$Workspaces=@()
$processes = Get-PowerBIWorkspace$id=0
ForEach ($process in $processes)
{$id++
$Workspaces+=New-Object PsObject -Property ([ordered]@{
Identity=$id
id=$process.Id
Name=$process.Name
})}# Second part of the command
$array = @()
foreach ($workspace in $Workspaces )
{
$Dataflow = Get-PowerBIDataFlow -Workspace $workspace
}Here, when i am passing values from $workspaces (created above) , it throws below error
Error as below
Get-PowerBIDataflow : Cannot bind parameter 'Workspace'. Cannot convert value "@{Identity=136; id=b2wewe8b5-wew2-4we-awew-awewe81a84f7; Name=PowerBI-Test}" to type "Microsoft.PowerBI.Common.Api.Workspaces.Workspace". Error: "Cannot convert the "@{Identity=136;
id=b2wewe8b5-wew2-4we-awew-awewe81a84f7; Name=PowerBI-Test }" value of type "System.Management.Automation.PSCustomObject" to type
"Microsoft.PowerBI.Common.Api.Workspaces.Workspace"."
At line:18 char:57
+ $Dataflow = Get-PowerBIDataFlow -Workspace $workspace
+ ~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-PowerBIDataflow], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerBI.Commands.Data.GetPowerBIDataflowAny suggestion on how to get rid of this error.
Thanks
Amit
- Kevin_MorganIron Contributor
Try the below script. The error message indicates that the command can't able to convert the custom ps object into Workspace object. So, we can use the parameter "WorkspaceId" and pass Workspace Id to get only dataflows belonging to that workspace.
$array = @() foreach ($workspace in $Workspaces ) { $Dataflow = Get-PowerBIDataFlow -WorkspaceId $workspace.id }