Public/SessionHost.ps1

Function Get-NmeHostPoolSessionHosts {
    <#
 
    .SYNOPSIS
 
    Get ARM host pool session hosts.
 
    .DESCRIPTION
 
    Get ARM host pool session hosts.
 
    This function calls the /api/v1/arm/hostpool/{subscriptionId}/{resourceGroup}/{hostPoolName}/host endpoint of the NME REST API, using the get method.
 
 
    .PARAMETER SubscriptionId
 
    The id (guid) of the subscription where this hostpool resides
 
    .PARAMETER ResourceGroup
 
    The Azure resource group where the hostpool resides
 
    .PARAMETER HostPoolName
 
    The name of the Host Pool
 
    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$SubscriptionId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$ResourceGroup,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostPoolName
    )
    Set-NmeAuthHeaders
    Try {
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/arm/hostpool/$SubscriptionId/$ResourceGroup/$HostPoolName/host$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json'
        $Result.PSObject.TypeNames.Insert(0, 'NmeArmSessionHost')
        $Result | ForEach-Object {$_ | Add-Member -NotePropertyName 'subscriptionId' -NotePropertyValue $subscriptionId -erroraction 'SilentlyContinue'}
        $Result | ForEach-Object {$_ | Add-Member -NotePropertyName 'resourceGroup' -NotePropertyValue $resourceGroup -erroraction 'SilentlyContinue'}
        $Result | ForEach-Object {$_ | Add-Member -NotePropertyName 'hostPoolName' -NotePropertyValue $hostPoolName -erroraction 'SilentlyContinue'}
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function New-NmeSessionHost {
    <#
 
    .SYNOPSIS
 
    Create ARM session host.
 
    .DESCRIPTION
 
    ### To choose more than one user to assign them to hosts in personal pool, write them in "userToAssign" field and separate them with comma [,]..
 
    This function calls the /api/v1/arm/hostpool/{subscriptionId}/{resourceGroup}/{hostPoolName}/host endpoint of the NME REST API, using the post method.
 
 
    .PARAMETER SubscriptionId
 
    The id (guid) of the subscription where this hostpool resides
 
    .PARAMETER ResourceGroup
 
    The Azure resource group where the hostpool resides
 
    .PARAMETER HostPoolName
 
    The name of the Host Pool
 
    .PARAMETER NmeCreateSessionHostRequest
 
    Requires an NmeCreateSessionHostRequest object, as generated by the New-NmeCreateSessionHostRequest command.
 
    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$SubscriptionId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$ResourceGroup,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostPoolName,
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeCreateSessionHostRequest"){$true} else{throw " is not a NmeCreateSessionHostRequest object."}})]$NmeCreateSessionHostRequest
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmeCreateSessionHostRequest | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/arm/hostpool/$SubscriptionId/$ResourceGroup/$HostPoolName/host$QueryString" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithMultipleJobs_BackwardCompatibility')
        $Result | Add-Member -NotePropertyName 'subscriptionId' -NotePropertyValue $subscriptionId -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'resourceGroup' -NotePropertyValue $resourceGroup -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostPoolName' -NotePropertyValue $hostPoolName -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Get-NmeSessionHost {
    <#
 
    .SYNOPSIS
 
    Get ARM session host by name.
 
    .DESCRIPTION
 
    Get ARM session host by name.
 
    This function calls the /api/v1/arm/hostpool/{subscriptionId}/{resourceGroup}/{hostPoolName}/host/{hostname} endpoint of the NME REST API, using the get method.
 
 
    .PARAMETER SubscriptionId
 
    The id (guid) of the subscription where this hostpool resides
 
    .PARAMETER ResourceGroup
 
    The Azure resource group where the hostpool resides
 
    .PARAMETER HostPoolName
 
    The name of the Host Pool
 
    .PARAMETER Hostname
 
    Name of AVD host
 
    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$SubscriptionId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$ResourceGroup,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostPoolName,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$Hostname
    )
    Set-NmeAuthHeaders
    Try {
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/arm/hostpool/$SubscriptionId/$ResourceGroup/$HostPoolName/host/$Hostname$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json'
        $Result.PSObject.TypeNames.Insert(0, 'NmeArmSessionHost')
        $Result | Add-Member -NotePropertyName 'subscriptionId' -NotePropertyValue $subscriptionId -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'resourceGroup' -NotePropertyValue $resourceGroup -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostPoolName' -NotePropertyValue $hostPoolName -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostname' -NotePropertyValue $hostname -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Remove-NmeSessionHost {
    <#
 
    .SYNOPSIS
 
    Remove ARM session host.
 
    .DESCRIPTION
 
    Remove ARM session host.
 
    This function calls the /api/v1/arm/hostpool/{subscriptionId}/{resourceGroup}/{hostPoolName}/host/{hostName} endpoint of the NME REST API, using the delete method.
 
 
    .PARAMETER SubscriptionId
 
    The id (guid) of the subscription where this hostpool resides
 
    .PARAMETER ResourceGroup
 
    The Azure resource group where the hostpool resides
 
    .PARAMETER HostPoolName
 
    The name of the Host Pool
 
    .PARAMETER HostName
 
    Name of AVD host
 
    .PARAMETER NmeRemoveSessionHostRequest
 
    Requires an NmeRemoveSessionHostRequest object, as generated by the New-NmeRemoveSessionHostRequest command.
 
    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$SubscriptionId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$ResourceGroup,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostPoolName,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostName,
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeRemoveSessionHostRequest"){$true} else{throw " is not a NmeRemoveSessionHostRequest object."}})]$NmeRemoveSessionHostRequest
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmeRemoveSessionHostRequest | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/arm/hostpool/$SubscriptionId/$ResourceGroup/$HostPoolName/host/$HostName$QueryString" -Method delete -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJob')
        $Result | Add-Member -NotePropertyName 'subscriptionId' -NotePropertyValue $subscriptionId -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'resourceGroup' -NotePropertyValue $resourceGroup -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostPoolName' -NotePropertyValue $hostPoolName -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostName' -NotePropertyValue $hostName -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Set-NmeSessionHostPowerState {
    <#
 
    .SYNOPSIS
 
    Start, restart or stop ARM session host VM.
 
    .DESCRIPTION
 
    Start, restart or stop ARM session host VM.
 
    This function calls the /api/v1/arm/hostpool/{subscriptionId}/{resourceGroup}/{hostPoolName}/host/{hostname}/power-state endpoint of the NME REST API, using the post method.
 
 
    .PARAMETER SubscriptionId
 
    The id (guid) of the subscription where this hostpool resides
 
    .PARAMETER ResourceGroup
 
    The Azure resource group where the hostpool resides
 
    .PARAMETER HostPoolName
 
    The name of the Host Pool
 
    .PARAMETER Hostname
 
    Name of AVD host
 
    .PARAMETER NmePowerStateCommandRequest
 
    Requires an NmePowerStateCommandRequest object, as generated by the New-NmePowerStateCommandRequest command.
 
    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$SubscriptionId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$ResourceGroup,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostPoolName,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$Hostname,
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmePowerStateCommandRequest"){$true} else{throw " is not a NmePowerStateCommandRequest object."}})]$NmePowerStateCommandRequest
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmePowerStateCommandRequest | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/arm/hostpool/$SubscriptionId/$ResourceGroup/$HostPoolName/host/$Hostname/power-state$QueryString" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJob')
        $Result | Add-Member -NotePropertyName 'subscriptionId' -NotePropertyValue $subscriptionId -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'resourceGroup' -NotePropertyValue $resourceGroup -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostPoolName' -NotePropertyValue $hostPoolName -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostname' -NotePropertyValue $hostname -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Start-NmeSessionHostReimageJob {
    <#
 
    .SYNOPSIS
 
    Re-image ARM session host VM.
 
    .DESCRIPTION
 
    Re-image ARM session host VM.
 
    This function calls the /api/v1/arm/hostpool/{subscriptionId}/{resourceGroup}/{hostPoolName}/host/{hostName}/reimage endpoint of the NME REST API, using the post method.
 
 
    .PARAMETER SubscriptionId
 
    The id (guid) of the subscription where this hostpool resides
 
    .PARAMETER ResourceGroup
 
    The Azure resource group where the hostpool resides
 
    .PARAMETER HostPoolName
 
    The name of the Host Pool
 
    .PARAMETER HostName
 
    Name of AVD host
 
    .PARAMETER NmeReimageHostRequest
 
    Requires an NmeReimageHostRequest object, as generated by the New-NmeReimageHostRequest command.
 
    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$SubscriptionId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$ResourceGroup,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostPoolName,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostName,
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmeReimageHostRequest"){$true} else{throw " is not a NmeReimageHostRequest object."}})]$NmeReimageHostRequest
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmeReimageHostRequest | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/arm/hostpool/$SubscriptionId/$ResourceGroup/$HostPoolName/host/$HostName/reimage$QueryString" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJob')
        $Result | Add-Member -NotePropertyName 'subscriptionId' -NotePropertyValue $subscriptionId -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'resourceGroup' -NotePropertyValue $resourceGroup -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostPoolName' -NotePropertyValue $hostPoolName -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostName' -NotePropertyValue $hostName -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Get-NmeSessionHostByAssignedUser {
    <#
 
    .SYNOPSIS
 
    Get ARM session host by assigned user.
 
    .DESCRIPTION
 
    Get ARM session host by assigned user.
 
    This function calls the /api/v1/arm/hostpool/{subscriptionId}/{resourceGroup}/{hostPoolName}/user/{username}/host endpoint of the NME REST API, using the get method.
 
 
    .PARAMETER SubscriptionId
 
    The id (guid) of the subscription where this hostpool resides
 
    .PARAMETER ResourceGroup
 
    The Azure resource group where the hostpool resides
 
    .PARAMETER HostPoolName
 
    The name of the Host Pool
 
    .PARAMETER Username
 
    Username of assigned user
 
    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$SubscriptionId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$ResourceGroup,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostPoolName,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$Username
    )
    Set-NmeAuthHeaders
    Try {
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/arm/hostpool/$SubscriptionId/$ResourceGroup/$HostPoolName/user/$Username/host$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json'
        $Result.PSObject.TypeNames.Insert(0, 'NmeArmSessionHost')
        $Result | Add-Member -NotePropertyName 'subscriptionId' -NotePropertyValue $subscriptionId -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'resourceGroup' -NotePropertyValue $resourceGroup -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostPoolName' -NotePropertyValue $hostPoolName -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'username' -NotePropertyValue $username -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Set-NmeUserSessionHostPowerState {
    <#
 
    .SYNOPSIS
 
    Start, restart or stop ARM personal session host VM.
 
    .DESCRIPTION
 
    Start, restart or stop ARM personal session host VM.
 
    This function calls the /api/v1/arm/hostpool/{subscriptionId}/{resourceGroup}/{hostPoolName}/user/{username}/host/power-state endpoint of the NME REST API, using the post method.
 
 
    .PARAMETER SubscriptionId
 
    The id (guid) of the subscription where this hostpool resides
 
    .PARAMETER ResourceGroup
 
    The Azure resource group where the hostpool resides
 
    .PARAMETER HostPoolName
 
    The name of the Host Pool
 
    .PARAMETER Username
 
    Username of assigned user
 
    .PARAMETER NmePowerStateCommandRequest
 
    Requires an NmePowerStateCommandRequest object, as generated by the New-NmePowerStateCommandRequest command.
 
    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$SubscriptionId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$ResourceGroup,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$HostPoolName,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$Username,
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$True)][ValidateScript({if ($_.PSObject.TypeNames -contains "NmePowerStateCommandRequest"){$true} else{throw " is not a NmePowerStateCommandRequest object."}})]$NmePowerStateCommandRequest
    )
    Set-NmeAuthHeaders
    Try {
        $json = $NmePowerStateCommandRequest | ConvertTo-Json -Depth 20
        Write-Debug 'json:'
        Write-Debug $json
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/arm/hostpool/$SubscriptionId/$ResourceGroup/$HostPoolName/user/$Username/host/power-state$QueryString" -Method post -Headers $script:AuthHeaders -ContentType 'application/json' -body $json
        Write-Verbose ($result | out-string)
        $Result.PSObject.TypeNames.Insert(0, 'NmeResponseWithJob')
        $Result | Add-Member -NotePropertyName 'subscriptionId' -NotePropertyValue $subscriptionId -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'resourceGroup' -NotePropertyValue $resourceGroup -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'hostPoolName' -NotePropertyValue $hostPoolName -erroraction 'SilentlyContinue'
        $Result | Add-Member -NotePropertyName 'username' -NotePropertyValue $username -erroraction 'SilentlyContinue'
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}
Function Get-NmeWorkspaceSessionHost {
    <#
 
    .SYNOPSIS
 
    Get ARM workspace session hosts.
 
    .DESCRIPTION
 
    Get ARM workspace session hosts.
 
    This function calls the /api/v1/arm/workspace/{subscriptionId}/{resourceGroup}/{workspaceName}/host endpoint of the NME REST API, using the get method.
 
 
    .PARAMETER SubscriptionId
 
    The id (guid) of the subscription where this workspace resides
 
    .PARAMETER ResourceGroup
 
    The Azure resource group where the workspace resides
 
    .PARAMETER WorkspaceName
 
    Name of the AVD Workspace
 
    .PARAMETER Username
 
    Username of assigned user
 
    #>


    [CmdletBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$SubscriptionId,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$ResourceGroup,
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)][string]$WorkspaceName,
        [Parameter(ValueFromPipelineByPropertyName=$true)][string]$Username
    )
    Set-NmeAuthHeaders
    Try {
        $QueryString = '?'
        $QueryStrings = @{}
        $QueryStrings += @{username= $username}
        $QueryString += ($QueryStrings.GetEnumerator() | % { "$($_.Key)=$($_.Value)" }) -join '&'
        $Result = Invoke-RestMethod "$script:NmeUri/api/v1/arm/workspace/$SubscriptionId/$ResourceGroup/$WorkspaceName/host$Querystring" -Method get -Headers $script:AuthHeaders -ContentType 'application/json'
        $Result.PSObject.TypeNames.Insert(0, 'NmeArmSessionHost')
        $Result | ForEach-Object {$_ | Add-Member -NotePropertyName 'subscriptionId' -NotePropertyValue $subscriptionId -erroraction 'SilentlyContinue'}
        $Result | ForEach-Object {$_ | Add-Member -NotePropertyName 'resourceGroup' -NotePropertyValue $resourceGroup -erroraction 'SilentlyContinue'}
        $Result | ForEach-Object {$_ | Add-Member -NotePropertyName 'workspaceName' -NotePropertyValue $workspaceName -erroraction 'SilentlyContinue'}
        $Result | CapProps
    }
    Catch {
        $message = ParseErrorForResponseBody($_)
        write-error ($message | out-string)
    }
}