Skip to content

Commit

Permalink
Merge pull request #172 from srozemuller/pipeline-change
Browse files Browse the repository at this point in the history
Pipeline change trigger
  • Loading branch information
srozemuller authored Feb 6, 2024
2 parents cb6e893 + 99f1694 commit 405819a
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 12 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ name: ModuleCompiler

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
pull_request:
branches: [ main ]
paths:
- az.avd/**
push:
tags:
- '*'

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/publisher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ name: Publisher

# Controls when the workflow will run
on:
pull_request:
types: [closed]
branches:
- 'main'

# Allows you to run this workflow manually from the Actions tab
push:
tags:
- '*'
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
Expand Down
3 changes: 2 additions & 1 deletion Az.Avd/Az.Avd.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
RootModule = 'Az.Avd.psm1'

# Version number of this module.
ModuleVersion = '3.1.1'
ModuleVersion = '3.2.0'

# Supported PSEditions
CompatiblePSEditions = 'Core', 'Desktop'
Expand Down Expand Up @@ -103,6 +103,7 @@
'Get-AvdSessionHost'
'Get-AvdSessionHostPowerState',
'Get-AvdSessionHostResources',
'Get-AvdUserAssignments',
'Get-AvdUserSessions',
'Get-AvdVmTemplate',
'Get-AvdWorkbook',
Expand Down
107 changes: 107 additions & 0 deletions Az.Avd/Public/Get-AvdUserAssignments.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
function Get-AvdUserAssignments {
<#
.SYNOPSIS
Searches for session host and its assignments.
.DESCRIPTION
This function will search all the sessionhost from a specific Azure Virtual Desktop hostpool regarding a user assignment.
.PARAMETER HostpoolName
Enter the AVD Hostpool name
.PARAMETER ResourceGroupName
Enter the AVD Hostpool resourcegroup name
.PARAMETER SessionHostName
Enter the sessionhosts name
.PARAMETER LoginName
Enter the user principal name
.EXAMPLE
Get-AvdUserAssignments -HostpoolName avd-hostpool-personal -ResourceGroupName rg-avd-01 -SessionHostName avd-host-1.avd.domain
.EXAMPLE
Get-AvdUserAssignments -HostpoolName avd-hostpool-personal -ResourceGroupName rg-avd-01 -SessionHostName avd-host-1.avd.domain -LoginName user@domain.com
#>
[CmdletBinding(DefaultParameterSetName = 'All')]
param
(
[parameter(Mandatory, ParameterSetName = 'All')]
[parameter(Mandatory, ParameterSetName = 'Hostname')]
[ValidateNotNullOrEmpty()]
[string]$HostpoolName,

[parameter(Mandatory, ParameterSetName = 'All')]
[parameter(Mandatory, ParameterSetName = 'Hostname')]
[ValidateNotNullOrEmpty()]
[string]$ResourceGroupName,

[parameter(Mandatory, ParameterSetName = 'Hostname')]
[ValidateNotNullOrEmpty()]
[string]$SessionHostName,

[parameter(ParameterSetName = 'All')]
[parameter(ParameterSetName = 'Hostname')]
[ValidateNotNullOrEmpty()]
[string]$LoginName,

[parameter(ParameterSetName = 'Id')]
[string]$SessionHostId
)
Begin {
Write-Verbose "Start searching session hosts"
AuthenticationCheck
$token = GetAuthToken -resource $global:AzureApiUrl
$baseUrl = $global:AzureApiUrl + "/subscriptions/" + $global:subscriptionId + "/resourceGroups/" + $ResourceGroupName + "/providers/Microsoft.DesktopVirtualization/hostpools/" + $HostpoolName + "/sessionHosts/"
$apiVersion = "?api-version=2022-02-10-preview"
}
Process {
switch ($PsCmdlet.ParameterSetName) {
All {
Write-Verbose "Searching for all sessions in $hostpoolName"
$SessionHostNames = Get-AvdSessionHost -HostpoolName $hostpoolName -ResourceGroupName $ResourceGroupName
$sessionHostUrl = [System.Collections.ArrayList]@()
$SessionHostNames | ForEach-Object {
$url = "{0}{1}" -f $global:AzureApiUrl, $_.id
$sessionHostUrl.Add($url) | Out-Null
}
}
Hostname {
Write-Verbose "Looking for sessionhost $SessionHostName"
$sessionHostUrl = "{0}{1}" -f $baseUrl, $SessionHostName
}
Id {
Write-Verbose "Looking for sessionhost on ID $SessionHostId"
$sessionHostUrl = "{0}{1}" -f $global:AzureApiUrl, $SessionHostId
}

}
try {
$sessionHostUrl | ForEach-Object {
Write-Verbose "Looking for assignments at $($_.Split("/")[-2])"
$parameters = @{
uri = "{0}{1}" -f $_, $apiVersion
Method = "GET"
Headers = $token
}

$assignmentList = [System.Collections.ArrayList]@()
$assignmentList.Add((Request-Api @parameters)) | Out-Null
}
if ($LoginName) {
$specificHosts = [System.Collections.ArrayList]@()
Write-Verbose "Searching for user with UPN $LoginName"
$assignmentList.ForEach({
$assignedHost = $_ | Where-Object { $_.Properties.assignedUser -eq $LoginName }
$specificHosts.Add($assignedHost) | Out-Null
})
if ($null -eq $assignmentList) {
Write-Information "User assigned user found with $LoginName at any session host in hostpool $HostpoolName"
}
else {
$specificHosts
}
}
else {
$assignmentList
}
}
catch {
"No sessions found. $_"
}
}
}

0 comments on commit 405819a

Please sign in to comment.