Skip to content

Commit 600f6b4

Browse files
committed
Import functions from powerrti project
1 parent 8c333c0 commit 600f6b4

32 files changed

+3158
-3
lines changed

FabricTools/FabricTools.psd1

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,33 @@
104104
"Resume-FabricCapacity",
105105
"Set-FabricAuthToken",
106106
"Suspend-FabricCapacity",
107-
"Unregister-FabricWorkspaceToCapacity"
107+
"Unregister-FabricWorkspaceToCapacity",
108+
109+
'Connect-FabricAccount',
110+
'Get-FabricEventhouse',
111+
'Get-FabricEventstream',
112+
'Get-FabricKQLDashboard',
113+
'Get-FabricKQLDatabase',
114+
'Get-FabricKQLQueryset',
115+
'Get-FabricWorkspace',
116+
'Invoke-FabricKQLCommand',
117+
'New-FabricEventhouse',
118+
'New-FabricEventstream',
119+
'New-FabricKQLDashboard',
120+
'New-FabricKQLDatabase',
121+
'New-FabricWorkspace',
122+
'Remove-FabricEventhouse',
123+
'Remove-FabricEventstream',
124+
'Remove-FabricKQLDatabase',
125+
'Remove-FabricKQLQueryset',
126+
'Set-FabricEventhouse',
127+
'Set-FabricEventstream',
128+
'Set-FabricKQLDatabase',
129+
'Set-FabricKQLQueryset',
130+
'Add-FabricWorkspaceRoleAssignment',
131+
'Get-FabricWorkspaceRoleAssignment',
132+
'Get-FabricKQLDashboardDefinition',
133+
'Get-FabricDebugInfo'
108134
)
109135

110136
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

FabricTools/FabricTools.psm1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@
2222
This script is part of the FabricTools module.
2323
#>
2424

25-
25+
$FabricSession = [ordered]@{
26+
BaseFabricUrl = 'https://api.fabric.microsoft.com'
27+
FabricToken = $null
28+
HeaderParams = $null
29+
ContentType = @{'Content-Type' = "application/json"}
30+
KustoURL = "https://api.kusto.windows.net"
31+
}
2632

2733
$script:apiUrl = "https://api.fabric.microsoft.com/v1"
2834
$script:resourceUrl = "https://api.fabric.microsoft.com"
@@ -51,3 +57,6 @@ Set-Alias -Name Get-FabricReport -Value Get-PowerBIReport
5157
Export-ModuleMember -Alias Get-FabricReport
5258
Set-Alias -Name Logout-Fabric -Value Logout-PowerBI
5359
Export-ModuleMember -Alias Logout-Fabric
60+
61+
$moduleName = 'FabricTools'
62+
Write-Host "Module $moduleName imported."
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
function Add-FabricWorkspaceRoleAssignment {
2+
#Requires -Version 7.1
3+
4+
<#
5+
.SYNOPSIS
6+
Adds a role assignment to a user in a workspace.
7+
8+
.DESCRIPTION
9+
Adds a role assignment to a user in a workspace. The User is identified by the principalId and the role is
10+
identified by the Role parameter. The Workspace is identified by the WorkspaceId.
11+
12+
.PARAMETER WorkspaceId
13+
Id of the Fabric Workspace for which the role assignment should be added. The value for WorkspaceId is a GUID.
14+
An example of a GUID is '12345678-1234-1234-1234-123456789012'. This parameter is mandatory.
15+
16+
.PARAMETER PrincipalId
17+
Id of the principal for which the role assignment should be added. The value for PrincipalId is a GUID.
18+
An example of a GUID is '12345678-1234-1234-1234-123456789012'. This parameter is mandatory. At the
19+
moment only principal type 'User' is supported.
20+
21+
.PARAMETER Role
22+
The role to assign to the principal. The value for Role is a string. An example of a string is 'Admin'.
23+
The values that can be used are 'Admin', 'Contributor', 'Member' and 'Viewer'.
24+
25+
26+
.EXAMPLE
27+
Add-RtiWorkspaceRoleAssignment `
28+
-WorkspaceId '12345678-1234-1234-1234-123456789012' `
29+
-PrincipalId '12345678-1234-1234-1234-123456789012' `
30+
-Role 'Admin'
31+
32+
.LINK
33+
https://learn.microsoft.com/en-us/rest/api/fabric/core/workspaces/add-workspace-role-assignment?tabs=HTTP
34+
35+
36+
.NOTES
37+
TODO: Add functionallity to add role assignments to groups.
38+
TODO: Add functionallity to add a user by SPN.
39+
#>
40+
41+
[CmdletBinding(SupportsShouldProcess)]
42+
param (
43+
44+
[Alias("Id")]
45+
[Parameter(Mandatory=$true)]
46+
[string]$WorkspaceId,
47+
48+
[Parameter(Mandatory=$true)]
49+
[string]$principalId,
50+
51+
[ValidateSet("Admin", "Contributor", "Member" , "Viewer")]
52+
[Parameter(Mandatory=$true)]
53+
[string]$Role
54+
)
55+
56+
begin {
57+
58+
# Check if session is established - if not throw error
59+
if ($null -eq $FabricSession.headerParams) {
60+
throw "No session established to Fabric Real-Time Intelligence. Please run Connect-RTISession"
61+
}
62+
63+
# Create body of request
64+
$body = @{
65+
'principal' = @{
66+
'id' = $principalId
67+
'type' = "User"
68+
}
69+
'role' = $Role
70+
} | ConvertTo-Json `
71+
-Depth 1
72+
73+
# Create Workspace API URL
74+
$workspaceApiUrl = "$($FabricSession.BaseFabricUrl)/v1/admin/workspaces/$WorkspaceId/roleassignments"
75+
}
76+
77+
process {
78+
79+
if($PSCmdlet.ShouldProcess($WorkspaceName)) {
80+
# Call Workspace API
81+
$response = Invoke-RestMethod `
82+
-Headers $FabricSession.headerParams `
83+
-Method POST `
84+
-Uri $WorkspaceApiUrl `
85+
-Body ($body) `
86+
-ContentType "application/json"
87+
88+
$response
89+
}
90+
}
91+
92+
end {}
93+
94+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
function Connect-FabricAccount {
2+
#Requires -Version 7.1
3+
4+
<#
5+
.SYNOPSIS
6+
Connects to the Fabric WebAPI.
7+
8+
.DESCRIPTION
9+
Connects to the Fabric WebAPI by using the cmdlet Connect-AzAccount.
10+
This function retrieves the authentication token for the Fabric API and sets up the headers for API calls.
11+
12+
.PARAMETER TenantId
13+
The TenantId of the Azure Active Directory tenant you want to connect to
14+
and in which your Fabric Capacity is.
15+
16+
.EXAMPLE
17+
Connect-RTIAccount `
18+
-TenantID '12345678-1234-1234-1234-123456789012'
19+
20+
.NOTES
21+
22+
Revsion History:
23+
24+
- 2024-12-22 - FGE: Added Verbose Output
25+
26+
.LINK
27+
Connect-AzAccount https://learn.microsoft.com/de-de/powershell/module/az.accounts/connect-azaccount?view=azps-12.4.0
28+
29+
#>
30+
31+
[CmdletBinding()]
32+
param (
33+
[Parameter(Mandatory=$true)]
34+
[string]$TenantId
35+
)
36+
37+
begin {
38+
}
39+
40+
process {
41+
Write-Verbose "Connect to Azure Account"
42+
Connect-AzAccount `
43+
-TenantId $TenantId | `
44+
Out-Null
45+
46+
Write-Verbose "Get authentication token"
47+
$FabricSession.FabricToken = (Get-AzAccessToken `
48+
-ResourceUrl $FabricSession.BaseFabricUrl).Token
49+
Write-Verbose "Token: $($FabricSession.FabricToken)"
50+
51+
Write-Verbose "Setup headers for API calls"
52+
$FabricSession.HeaderParams = @{'Authorization'="Bearer {0}" -f $FabricSession.FabricToken}
53+
Write-Verbose "HeaderParams: $($FabricSession.HeaderParams)"
54+
}
55+
56+
end {
57+
}
58+
59+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function Get-FabricDebugInfo {
2+
#Requires -Version 7.1
3+
4+
<#
5+
.SYNOPSIS
6+
Shows internal debug information about the current session.
7+
8+
.DESCRIPTION
9+
Shows internal debug information about the current session. It is useful for troubleshooting purposes.
10+
It will show you the current session object. This includes the bearer token. This can be useful
11+
for connecting to the REST API directly via Postman.
12+
13+
.Example
14+
Get-FabricDebugInfo
15+
16+
This example shows the current session object.
17+
18+
.NOTES
19+
20+
Revsion History:
21+
22+
- 2024-12-22 - FGE: Added Verbose Output
23+
24+
#>
25+
26+
[CmdletBinding()]
27+
param (
28+
29+
)
30+
31+
begin {
32+
}
33+
34+
process {
35+
Write-Verbose "Show current session object"
36+
$FabricSession
37+
}
38+
39+
end {
40+
}
41+
42+
}

0 commit comments

Comments
 (0)