diff --git a/.gitignore b/.gitignore index 4c0bf62..639bf07 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,4 @@ Modules/PowerBIETL/PublishToGallery.ps1 /.vs/slnx.sqlite /.vs -ImportPBIStuff.ps1 +Test*.ps1 diff --git a/Modules/PowerBIPS/PowerBIPS.psd1 b/Modules/PowerBIPS/PowerBIPS.psd1 index ce5fb59..4c787b8 100644 --- a/Modules/PowerBIPS/PowerBIPS.psd1 +++ b/Modules/PowerBIPS/PowerBIPS.psd1 @@ -72,6 +72,8 @@ FunctionsToExport = @( , "Get-PBIDatasources", "Invoke-PBIRequest", "Get-PBIModuleConfig", "Set-PBIModuleConfig" , "Set-PBIReportContent", "Get-PBIAuthTokenHttp", "Remove-PBIDataSet" , "Remove-PBIReport" + , "Get-PBICapacities", "Set-PBICapacity", "Clear-PBICapacity","Get-PBICapacityAssignmentStatus" + , "Get-PBICapacityWorkloads", "Set-PBICapacityWorkload" ) # Cmdlets to export from this module diff --git a/Modules/PowerBIPS/PowerBIPS.psm1 b/Modules/PowerBIPS/PowerBIPS.psm1 index aaf5f09..efae93e 100644 --- a/Modules/PowerBIPS/PowerBIPS.psm1 +++ b/Modules/PowerBIPS/PowerBIPS.psm1 @@ -2211,6 +2211,271 @@ Function Get-PBIDatasources{ } } +#region Capacities + +Function Get-PBICapacities{ +<# +.SYNOPSIS + Gets an array of avaliable capacities the user has access to +.DESCRIPTION + Gets an array of avaliable capacities the user has access to +.PARAMETER AuthToken + The authorization token required to communicate with the PowerBI APIs + Use 'Get-PBIAuthToken' to get the authorization token string +.EXAMPLE + Get-PBICapacities -authToken $authtoken +#> + [CmdletBinding()] + param( + [Parameter(Mandatory=$false)] [string] $authToken + ) + + Write-Verbose "Getting Capacities" + + $resource = "capacities" + + $capacities = @(Invoke-PBIRequest -authToken $authToken -method Get -resource $resource -ignoreGroup) + + Write-Verbose "Found $($capacities.count) capacities." + + Write-Output $capacities +} + +Function Set-PBICapacity{ +<# +.SYNOPSIS + Assigns the specified workspace to the specified capacity +.DESCRIPTION + Assigns the specified workspace to the specified capacity. + Note: To perform this operation, the user must be admin on the specified workspace and have admin or assign permissions on the capacity. +.PARAMETER AuthToken + The authorization token required to communicate with the PowerBI APIs + Use 'Get-PBIAuthToken' to get the authorization token string +.PARAMETER Capacity + The Capacity object or the capacity ID (GUID) +.PARAMETER GroupId + Id (GUID) of the workspace to which the capacity will be assigned +.EXAMPLE + Set-PBICapacity -authToken $authtoken -capacity {your_capacity} +#> + [CmdletBinding()] + param( + [Parameter(Mandatory=$false)] [string] $authToken, + [Parameter(Mandatory=$true, ValueFromPipeline = $true)] $capacity, + [Parameter(Mandatory=$false)] [string] $groupId + ) + begin {} + process + { + $capacityId = "" + if ($capacity -is [string]) + { + $capacityId = $capacity + } + else + { + $capacityId = $capacity.id + } + + Write-Verbose "Assigning Capacity" + + $resource = "AssignToCapacity" + + $bodyObj = @{capacityId=$capacityId} + + $capacities = @(Invoke-PBIRequest -authToken $authToken -method Post -resource $resource -Body ($bodyObj | ConvertTo-Json) -groupId $groupId) + + Write-Verbose "Assigned Capacity $($capacity.displayName) $($capacity.id)." + + Write-Output $capacities + } +} + +Function Clear-PBICapacity{ +<# +.SYNOPSIS + Unassign currently assigned capacity +.DESCRIPTION + Unassign currently assigned capacity +.PARAMETER AuthToken + The authorization token required to communicate with the PowerBI APIs + Use 'Get-PBIAuthToken' to get the authorization token string +.PARAMETER GroupId + Id (GUID) of the workspace to which the capacity will be unassigned +.EXAMPLE + Clear-PBICapacity -authToken $authtoken +#> + [CmdletBinding()] + param( + [Parameter(Mandatory=$false)] [string] $authToken, + [Parameter(Mandatory=$false)] [string] $groupId + ) + begin {} + process + { + Write-Verbose "Unassigning Capacity" + + $capacityId = "00000000-0000-0000-0000-000000000000" + + $resource = "AssignToCapacity" + + $bodyObj = @{capacityId=$capacityId} + + $capacities = @(Invoke-PBIRequest -authToken $authToken -method Post -resource $resource -Body ($bodyObj | ConvertTo-Json) -groupId $groupId) + + Write-Verbose "Unassigned Capacity." + + Write-Output $capacities + } +} + +Function Get-PBICapacityAssignmentStatus{ +<# +.SYNOPSIS + Gets the status of the assignment to capacity operation of the specified workspace +.DESCRIPTION + Gets the status of the assignment to capacity operation of the specified workspace. + Note: To perform this operation, the user must be admin on the specified workspace. +.PARAMETER AuthToken + The authorization token required to communicate with the PowerBI APIs + Use 'Get-PBIAuthToken' to get the authorization token string +.PARAMETER GroupId + Id (GUID) of the workspace to which the capacity will be unassigned +.EXAMPLE + Get-PBICapacityAssignmentStatus -authToken $authtoken +#> + [CmdletBinding()] + param( + [Parameter(Mandatory=$false)] [string] $authToken, + [Parameter(Mandatory=$false)] [string] $groupId + ) + + Write-Verbose "Getting Capacity Assignment Status" + + $resource = "CapacityAssignmentStatus" + + $capacityStatus = @(Invoke-PBIRequest -authToken $authToken -method Get -resource $resource) + + Write-Output $capacityStatus +} + +Function Get-PBICapacityWorkloads{ +<# +.SYNOPSIS + Returns the current state of the specified capacity workloads. +.DESCRIPTION + Returns the current state of the specified capacity workloads. + If a workload is enabled also returns the maximum memory percentage that the workload can consume. +.PARAMETER AuthToken + The authorization token required to communicate with the PowerBI APIs + Use 'Get-PBIAuthToken' to get the authorization token string +.PARAMETER Capacity + The Capacity object or the capacity ID (GUID) +.PARAMETER WorkloadName + The workload name +.EXAMPLE + Get-PBICapacityWorkloads -authToken $authtoken -capacity $capacity +#> + [CmdletBinding()] + param( + [Parameter(Mandatory=$false)] [string] $authToken, + [Parameter(Mandatory=$true, ValueFromPipeline = $true)] $capacity, + [Parameter(Mandatory=$false)] [string] $workloadName + ) + + $capacityId = "" + if ($capacity -is [string]) + { + $capacityId = $capacity + } + else + { + $capacityId = $capacity.id + } + + Write-Verbose "Getting Capacity Workloads" + + $resource = "capacities/$capacityId/Workloads" + + if (![string]::IsNullOrEmpty($workloadName)) + { + $resource += "/$workloadName" + } + + $workloads = @(Invoke-PBIRequest -authToken $authToken -method Get -resource $resource -ignoreGroup) + + Write-Verbose "Found $($workloads.count) workloads." + + Write-Output $workloads +} + +Function Set-PBICapacityWorkload{ +<# +.SYNOPSIS + Changes the state and/or maximum memory percentage of the specified workload +.DESCRIPTION + Changes the state of a specific workload to Enabled or Disabled. + When enabling a workload the maximum memory percentage that the workload can consume must be set. +.PARAMETER AuthToken + The authorization token required to communicate with the PowerBI APIs + Use 'Get-PBIAuthToken' to get the authorization token string +.PARAMETER Capacity + The Capacity object or the capacity ID (GUID) +.PARAMETER WorkloadName + The workload name +.PARAMETER Disable + By default, the cmdlet will Enable the workload. Use -disable to Disable it. +.PARAMETER maxMemoryPercentageSetByUser + The memory percentage maximum limit set by the user. Mandatory if you are gonna Enable the workload. +.EXAMPLE + Set-PBICapacityWorkload -authToken $authtoken -capacity $capacity -workloadName "Dataflows" -maxMemoryPercentageSetByUser 20 +.EXAMPLE + Set-PBICapacityWorkload -authToken $authtoken -capacity $capacity -workloadName "Dataflows" -disable +#> + [CmdletBinding()] + param( + [Parameter(Mandatory=$false)] [string] $authToken, + [Parameter(Mandatory=$true, ValueFromPipeline = $true)] $capacity, + [Parameter(Mandatory=$true)] [string] $workloadName, + [Parameter(Mandatory=$false)] [switch] $disable, + [Parameter(Mandatory=$false)] [int] $maxMemoryPercentageSetByUser, + [Parameter(Mandatory=$false)] [string] $groupId + ) + begin {} + process + { + $capacityId = "" + if ($capacity -is [string]) + { + $capacityId = $capacity + } + else + { + $capacityId = $capacity.id + } + + if ($disable){ + $bodyObj = @{ + state = "Disabled" + } + } + else { + $bodyObj = @{ + state = "Enabled" + maxMemoryPercentageSetByUser = "$maxMemoryPercentageSetByUser" + } + } + + $resource = "capacities/$capacityId/Workloads/$workloadName" + + Invoke-PBIRequest -authToken $authToken -method Patch -resource $resource -Body ($bodyObj | ConvertTo-Json) -ignoreGroup + + Write-Verbose "$workloadName Workload changed" + } +} + +#endregion + Function Invoke-PBIRequest{ <# .SYNOPSIS diff --git a/Modules/PowerBIPS/doc/Clear-PBICapacity.md b/Modules/PowerBIPS/doc/Clear-PBICapacity.md new file mode 100644 index 0000000..53a67f5 --- /dev/null +++ b/Modules/PowerBIPS/doc/Clear-PBICapacity.md @@ -0,0 +1,71 @@ +--- +external help file: PowerBIPS-help.xml +Module Name: PowerBIPS +online version: +schema: 2.0.0 +--- + +# Clear-PBICapacity + +## SYNOPSIS +Unassign currently assigned capacity + +## SYNTAX + +``` +Clear-PBICapacity [[-authToken] ] [[-groupId] ] [] +``` + +## DESCRIPTION +Unassign currently assigned capacity + +## EXAMPLES + +### EXAMPLE 1 +``` +Clear-PBICapacity -authToken $authtoken +``` + +## PARAMETERS + +### -authToken +The authorization token required to communicate with the PowerBI APIs +Use 'Get-PBIAuthToken' to get the authorization token string + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -groupId +Id (GUID) of the workspace to which the capacity will be unassigned + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/Modules/PowerBIPS/doc/Get-PBICapacities.md b/Modules/PowerBIPS/doc/Get-PBICapacities.md new file mode 100644 index 0000000..a3074da --- /dev/null +++ b/Modules/PowerBIPS/doc/Get-PBICapacities.md @@ -0,0 +1,56 @@ +--- +external help file: PowerBIPS-help.xml +Module Name: PowerBIPS +online version: +schema: 2.0.0 +--- + +# Get-PBICapacities + +## SYNOPSIS +Gets an array of avaliable capacities the user has access to + +## SYNTAX + +``` +Get-PBICapacities [[-authToken] ] [] +``` + +## DESCRIPTION +Gets an array of avaliable capacities the user has access to + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-PBICapacities -authToken $authtoken +``` + +## PARAMETERS + +### -authToken +The authorization token required to communicate with the PowerBI APIs +Use 'Get-PBIAuthToken' to get the authorization token string + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/Modules/PowerBIPS/doc/Get-PBICapacityAssignmentStatus.md b/Modules/PowerBIPS/doc/Get-PBICapacityAssignmentStatus.md new file mode 100644 index 0000000..4a69a7e --- /dev/null +++ b/Modules/PowerBIPS/doc/Get-PBICapacityAssignmentStatus.md @@ -0,0 +1,72 @@ +--- +external help file: PowerBIPS-help.xml +Module Name: PowerBIPS +online version: +schema: 2.0.0 +--- + +# Get-PBICapacityAssignmentStatus + +## SYNOPSIS +Gets the status of the assignment to capacity operation of the specified workspace + +## SYNTAX + +``` +Get-PBICapacityAssignmentStatus [[-authToken] ] [[-groupId] ] [] +``` + +## DESCRIPTION +Gets the status of the assignment to capacity operation of the specified workspace. +Note: To perform this operation, the user must be admin on the specified workspace. + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-PBICapacityAssignmentStatus -authToken $authtoken +``` + +## PARAMETERS + +### -authToken +The authorization token required to communicate with the PowerBI APIs +Use 'Get-PBIAuthToken' to get the authorization token string + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -groupId +Id (GUID) of the workspace to which the capacity will be unassigned + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/Modules/PowerBIPS/doc/Get-PBICapacityWorkloads.md b/Modules/PowerBIPS/doc/Get-PBICapacityWorkloads.md new file mode 100644 index 0000000..85962b3 --- /dev/null +++ b/Modules/PowerBIPS/doc/Get-PBICapacityWorkloads.md @@ -0,0 +1,88 @@ +--- +external help file: PowerBIPS-help.xml +Module Name: PowerBIPS +online version: +schema: 2.0.0 +--- + +# Get-PBICapacityWorkloads + +## SYNOPSIS +Returns the current state of the specified capacity workloads. + +## SYNTAX + +``` +Get-PBICapacityWorkloads [[-authToken] ] [-capacity] [[-workloadName] ] + [] +``` + +## DESCRIPTION +Returns the current state of the specified capacity workloads. +If a workload is enabled also returns the maximum memory percentage that the workload can consume. + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-PBICapacityWorkloads -authToken $authtoken -capacity $capacity +``` + +## PARAMETERS + +### -authToken +The authorization token required to communicate with the PowerBI APIs +Use 'Get-PBIAuthToken' to get the authorization token string + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -capacity +The Capacity object or the capacity ID (GUID) + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -workloadName +The workload name + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/Modules/PowerBIPS/doc/Set-PBICapacity.md b/Modules/PowerBIPS/doc/Set-PBICapacity.md new file mode 100644 index 0000000..ceab19d --- /dev/null +++ b/Modules/PowerBIPS/doc/Set-PBICapacity.md @@ -0,0 +1,87 @@ +--- +external help file: PowerBIPS-help.xml +Module Name: PowerBIPS +online version: +schema: 2.0.0 +--- + +# Set-PBICapacity + +## SYNOPSIS +Assigns the specified workspace to the specified capacity + +## SYNTAX + +``` +Set-PBICapacity [[-authToken] ] [-capacity] [[-groupId] ] [] +``` + +## DESCRIPTION +Assigns the specified workspace to the specified capacity. +Note: To perform this operation, the user must be admin on the specified workspace and have admin or assign permissions on the capacity. + +## EXAMPLES + +### EXAMPLE 1 +``` +Set-PBICapacity -authToken $authtoken -capacity {your_capacity} +``` + +## PARAMETERS + +### -authToken +The authorization token required to communicate with the PowerBI APIs +Use 'Get-PBIAuthToken' to get the authorization token string + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -capacity +The Capacity object or the capacity ID (GUID) + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -groupId +Id (GUID) of the workspace to which the capacity will be assigned + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/Modules/PowerBIPS/doc/Set-PBICapacityWorkload.md b/Modules/PowerBIPS/doc/Set-PBICapacityWorkload.md new file mode 100644 index 0000000..ebab09c --- /dev/null +++ b/Modules/PowerBIPS/doc/Set-PBICapacityWorkload.md @@ -0,0 +1,140 @@ +--- +external help file: PowerBIPS-help.xml +Module Name: PowerBIPS +online version: +schema: 2.0.0 +--- + +# Set-PBICapacityWorkload + +## SYNOPSIS +Changes the state and/or maximum memory percentage of the specified workload + +## SYNTAX + +``` +Set-PBICapacityWorkload [[-authToken] ] [-capacity] [-workloadName] [-disable] + [[-maxMemoryPercentageSetByUser] ] [[-groupId] ] [] +``` + +## DESCRIPTION +Changes the state of a specific workload to Enabled or Disabled. +When enabling a workload the maximum memory percentage that the workload can consume must be set. + +## EXAMPLES + +### EXAMPLE 1 +``` +Set-PBICapacityWorkload -authToken $authtoken -capacity $capacity -workloadName "Dataflows" -maxMemoryPercentageSetByUser 20 +``` + +### EXAMPLE 2 +``` +Set-PBICapacityWorkload -authToken $authtoken -capacity $capacity -workloadName "Dataflows" -disable +``` + +## PARAMETERS + +### -authToken +The authorization token required to communicate with the PowerBI APIs +Use 'Get-PBIAuthToken' to get the authorization token string + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -capacity +The Capacity object or the capacity ID (GUID) + +```yaml +Type: Object +Parameter Sets: (All) +Aliases: + +Required: True +Position: 2 +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -workloadName +The workload name + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 3 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -disable +By default, the cmdlet will Enable the workload. +Use -disable to Disable it. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -maxMemoryPercentageSetByUser +The memory percentage maximum limit set by the user. +Mandatory if you are gonna Enable the workload. + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: 0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -groupId +{{ Fill groupId Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 5 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS