diff --git a/Horizon Tools/KISHorizon.psm1 b/Horizon Tools/KISHorizon.psm1 index 8a35de3..2d021bb 100644 --- a/Horizon Tools/KISHorizon.psm1 +++ b/Horizon Tools/KISHorizon.psm1 @@ -539,6 +539,7 @@ Function Get-HorizonADUser { [string]$Domain = "", [string]$Id = "", [string]$Name = "", + [string]$UPN = "", [int]$Page = 0, [int]$PageSize = 0 ) @@ -567,15 +568,17 @@ Function Get-HorizonADUser { } 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 if ($global:kishorizondebug) { Write-Host $MyInvocation.MyCommand.Name Starting - Write-Host User: $Name - Write-Host Domain: $Domain } try { @@ -592,7 +595,7 @@ Function Get-HorizonADUser { } return $users -} +} function Invoke-SSHCommand { param ( @@ -680,7 +683,8 @@ function Grant-HorizonDesktop { param ( [parameter(Mandatory = $true, ValueFromPipeline = $true)] $Horizon, [parameter(Mandatory = $true)] $MachineName, - [parameter(Mandatory = $true)] $UserUPN + [string] $UserUPN = "", + [string] $UserName = "" ) $token = $Horizon.access_token $server = $Horizon.server_name @@ -691,6 +695,13 @@ function Grant-HorizonDesktop { if ($global:kishorizondebug) { 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 if ($global:kishorizondebug) { @@ -699,22 +710,23 @@ function Grant-HorizonDesktop { if ($MachineID -eq $null) { return [PSCustomObject]@{ 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) { - $UserID = (Get-HorizonAdUser -Horizon $Horizon -Name $nameparts[1] -domain $nameparts[0]).id + + if ($UserName -ne "") { + $UserID = (Get-HorizonAdUser -Horizon $Horizon -UserName $Name).id } else { - $UserID = (Get-HorizonAdUser -Horizon $Horizon -Name $UseUPN).id + $UserID = (Get-HorizonAdUser -Horizon $Horizon -UPN $UserUPN).id } + if ($global:kishorizondebug) { Write-Host UserID: $UserID } if ($UserID -eq $null) { return [PSCustomObject]@{ Success = $false - Message = "User $UserUPN cannot be found." + Message = User $UserUPN cannot be found. } }