Skip to content

Commit 9f4f1e9

Browse files
committed
Invoke-FabricRestMethod can execute PowerBI API when needed
Fixed Get-FabricWorkspaceUsers function
1 parent 8e23ccd commit 9f4f1e9

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

helper/GetFunctionList.ps1

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
$path = ".\FabricTools\public"
1+
$path = ".\source\public"
22
$op = Get-ChildItem -Path $path -Recurse -Filter *.ps1 | Select-Object -ExpandProperty Name | Sort-Object
33
#$op = $op | ForEach-Object { " ""$_""," }
44
$op | Out-File '.\Output\FunctionList-main-public.txt'
55

6-
$path = ".\FabricTools\tiago\public"
7-
$tp = Get-ChildItem -Path $path -Recurse -Filter *.ps1 | Select-Object -ExpandProperty Name | Sort-Object
8-
$tp | Out-File '.\Output\FunctionList-tiago-public.txt'
6+
# Author Table
7+
# This script generates a table of PowerShell script authors from the specified directory.
8+
$authorTable = @{}
9+
$op | ForEach-Object {
10+
$file = $_.FullName
11+
$name = $_.Name
12+
$content = Get-Content $file
13+
$authorLine = $content | Where-Object { $_ -match 'Author:\s*(.+)' } | Select-Object -First 1
14+
if ($authorLine -match 'Author:\s*(.+)') {
15+
$author = $matches[1].Trim()
16+
$authorTable[$name] = $author
17+
} else {
18+
$authorTable[$name] = $null
19+
}
20+
}
21+
$authorTable
922

10-
$common = Compare-Object -ReferenceObject $op -DifferenceObject $tp -IncludeEqual -ExcludeDifferent | Select-Object -ExpandProperty InputObject
11-
$common
12-
$common | Out-File '.\Output\FunctionList-public-collision.txt'
23+
## Not a singular name option for functions (#26)
24+
Get-Command -Module FabricTools |where Name -like '*s'
25+
Get-Command -Module FabricTools|ForEach-Object { $name = $_.Name; $_.Parameters.Values | Where Name -like '*s' | Select @{N='FunctionName';E={$Name}},Name}

source/Public/Invoke-FabricRestMethod.ps1

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ Function Invoke-FabricRestMethod {
1919
.PARAMETER TestTokenExpired
2020
A switch parameter to test if the Fabric token is expired before making the request. If the token is expired, it will attempt to refresh it.
2121
22+
.PARAMETER PowerBIApi
23+
A switch parameter to indicate that the request should be sent to the Power BI API instead of the Fabric API.
24+
2225
.EXAMPLE
2326
Invoke-FabricRestMethod -uri "/api/resource" -method "GET"
2427
@@ -47,17 +50,27 @@ Function Invoke-FabricRestMethod {
4750
[Parameter(Mandatory = $false)]
4851
$Body,
4952

50-
[switch] $TestTokenExpired
53+
[switch] $TestTokenExpired,
54+
55+
[switch] $PowerBIApi
5156
)
5257

5358
if ($TestTokenExpired) {
5459
Test-TokenExpired
5560
}
5661

62+
$baseUrl = $FabricConfig.BaseUrl
63+
if ($PowerBIApi) {
64+
$baseUrl = $PowerBI.BaseApiUrl
65+
}
66+
5767
if ($Uri -notmatch '^https?://.*') {
58-
$Uri = "{0}/{1}" -f $FabricConfig.BaseUrl, $Uri
68+
$Uri = "{0}/{1}" -f $baseUrl, $Uri
69+
if ($PowerBIApi) {
70+
Write-Message -Message "PowerBIApi param is ignored when full Uri is provided." -Level Warning
71+
}
5972
}
60-
Write-Message -Message "Fabric API Endpoint: $Uri" -Level Verbose
73+
Write-Message -Message "Target API Endpoint: $Uri" -Level Verbose
6174

6275
if ($Body -is [hashtable]) {
6376
$Body = $Body | ConvertTo-Json -Depth 10

source/Public/Workspace/Get-FabricWorkspaceUsers.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ The function defines parameters for the workspace ID and workspace object. If th
4444
}
4545

4646
process {
47-
# If the parameter set name is 'WorkspaceId', retrieve the workspace object.
48-
if ($PSCmdlet.ParameterSetName -eq 'WorkspaceId') {
49-
$workspace = Get-PowerBIWorkspace -Id $WorkspaceId
47+
# If the parameter set name is 'WorkspaceObject', retrieve the workspace object.
48+
if ($PSCmdlet.ParameterSetName -eq 'WorkspaceObject') {
49+
$WorkspaceId = $Workspace.id
5050
}
5151

5252
# Make a GET request to the PowerBI API to retrieve the users of the workspace.
5353
# The function returns the 'value' property of the response, which contains the users.
54-
return (Invoke-FabricRestMethod -Method get -uri ("groups/$($workspace.Id)/users") | ConvertFrom-Json).value
54+
return (Invoke-FabricRestMethod -Method get -PowerBIApi -uri ("groups/$WorkspaceId/users")).value
5555
}
5656

5757
}

0 commit comments

Comments
 (0)