Update KISHorizon.psm1

This commit is contained in:
ackitsme committed 2026-09-11 17:06:39 -07:00
1 parent 205d434afc
commit e6bb5f2e14
1 file changed
+23 -11
+23 -11
View File
@@ -539,6 +539,7 @@ Function Get-HorizonADUser {
[string]$Domain = "", [string]$Domain = "",
[string]$Id = "", [string]$Id = "",
[string]$Name = "", [string]$Name = "",
[string]$UPN = "",
[int]$Page = 0, [int]$Page = 0,
[int]$PageSize = 0 [int]$PageSize = 0
) )
@@ -567,15 +568,17 @@ Function Get-HorizonADUser {
} }
if ($Name -ne "") { if ($Name -ne "") {
$extension = "?group_only=false&filter={`"type`":`"Or`",`"filters`":[{`"type`":`"Equals`",`"name`":`"user_principal_name`",`"value`":`"$Name`"},{`"type`":`"Equals`",`"name`":`"login_name`",`"value`":`"$Name`"}]}" $extension = "?group_only=false&filter={`"type`":`"Equals`",`"name`":`"login_name`",`"value`":`"$Name`"}"
}
if ($UPN -ne "") {
$extension = "?group_only=false&filter={`"type`":`"Equals`",`"name`":`"user_principal_name`",`"value`":`"$UPN`"}"
} }
$userlookupURI += $extension $userlookupURI += $extension
if ($global:kishorizondebug) { if ($global:kishorizondebug) {
Write-Host $MyInvocation.MyCommand.Name Starting Write-Host $MyInvocation.MyCommand.Name Starting
Write-Host User: $Name
Write-Host Domain: $Domain
} }
try { try {
@@ -592,7 +595,7 @@ Function Get-HorizonADUser {
} }
return $users return $users
} }
function Invoke-SSHCommand { function Invoke-SSHCommand {
param ( param (
@@ -680,7 +683,8 @@ function Grant-HorizonDesktop {
param ( param (
[parameter(Mandatory = $true, ValueFromPipeline = $true)] $Horizon, [parameter(Mandatory = $true, ValueFromPipeline = $true)] $Horizon,
[parameter(Mandatory = $true)] $MachineName, [parameter(Mandatory = $true)] $MachineName,
[parameter(Mandatory = $true)] $UserUPN [string] $UserUPN = "",
[string] $UserName = ""
) )
$token = $Horizon.access_token $token = $Horizon.access_token
$server = $Horizon.server_name $server = $Horizon.server_name
@@ -691,6 +695,13 @@ function Grant-HorizonDesktop {
if ($global:kishorizondebug) { if ($global:kishorizondebug) {
Write-Host $MyInvocation.MyCommand.Name Starting Write-Host $MyInvocation.MyCommand.Name Starting
} }
if ($UserUPN -eq "" -and $UserName -eq "") {
return [PSCustomObject]@{
Success = $false
Message = Neither UserName nor UserUPN were provided.
}
}
$MachineID = (Get-HorizonMachine -Horizon $Horizon | where {$_.name -eq $MachineName}).id $MachineID = (Get-HorizonMachine -Horizon $Horizon | where {$_.name -eq $MachineName}).id
if ($global:kishorizondebug) { if ($global:kishorizondebug) {
@@ -699,22 +710,23 @@ function Grant-HorizonDesktop {
if ($MachineID -eq $null) { if ($MachineID -eq $null) {
return [PSCustomObject]@{ return [PSCustomObject]@{
Success = $false Success = $false
Message = "Machine $MachineName does not exist in any desktop pool." Message = Machine $MachneName does not exist in any desktop pool.
} }
} }
$nameparts = $UserUPN.split("\")
if ($nameparts.Count -gt 1) { if ($UserName -ne "") {
$UserID = (Get-HorizonAdUser -Horizon $Horizon -Name $nameparts[1] -domain $nameparts[0]).id $UserID = (Get-HorizonAdUser -Horizon $Horizon -UserName $Name).id
} else { } else {
$UserID = (Get-HorizonAdUser -Horizon $Horizon -Name $UseUPN).id $UserID = (Get-HorizonAdUser -Horizon $Horizon -UPN $UserUPN).id
} }
if ($global:kishorizondebug) { if ($global:kishorizondebug) {
Write-Host UserID: $UserID Write-Host UserID: $UserID
} }
if ($UserID -eq $null) { if ($UserID -eq $null) {
return [PSCustomObject]@{ return [PSCustomObject]@{
Success = $false Success = $false
Message = "User $UserUPN cannot be found." Message = User $UserUPN cannot be found.
} }
} }