Adding Azure Remote App Users with PowerShell

16 February, 2017

Adding azure remote app users with PowerShell is a relatively simple task and many times quicker than waiting for the clunky web based UI. The first thing to do is install the ‘Microsoft Azure PowerShell module’.

Once you have this module installed you need to add an Azure account. You only ever need to do this once. It’s as simple as running the following cmdlet and signing in.

Add-AzureAccount

Once you have signed in you will need to select the subscription that you want to add the user to. You can get a list of all you subscriptions using:

Get-AzureSubscription

select a subscription use the following:

Select-AzureSubscription <Subscription Name>

Once you have selected your subscription you can begin to add users. This is as simple as running:

add-AzureRemoteAppUser -CollectionName <Collection Name> -Type orgid -Userupn <User UPN/Email>

This will then add the user to the selected collection under the selected subscription and allow them to start using remote apps.

Log Off an Azure Remote App User via PowerShell

15 November, 2016

I wrote this script because Azure Remote App is shit and always causes problems for users. One of the bigger problems is when a user’s application within Azure Remote App freezes, the user can’t simple restart the remote app as the server keeps the session and frozen/crashed application alive.

The solution to this is to log the user off the server. This module is designed to be a super simple way to log off a user just by using their email address that is associated with the Azure Remote App account.

function global:end-azureSession{
    Param(
        [parameter(HelpMessage='your username/email for azure')]
        [string]$userEmail,
        [parameter(HelpMessage='your password for azure')]
        [string]$cred
    )

    #define our set variables for the penrith enviroment
    $azureSubscription = 'PCC-AAE'

    #create credentials
    #$secPass = ConvertTo-SecureString $password -AsPlainText -Force
    if($cred){
        #$AzureCred = New-Object System.Management.Automation.PSCredential ($username, $secPass)
    }else{
        $cred = Get-Credential
        #$AzureCred = New-Object System.Management.Automation.PSCredential
    }
    #this will throw exception even if success.... so yep... this is my work-around...
    try{Add-AzureAccount -Credential $cred}catch{write-host "Connected to Azure" -ForegroundColor green}

    #Select subscription
    Select-AzureSubscription $azureSubscription

    #disconnect user
    write-host "Disconnecting user, this may take a while....." -ForegroundColor green
    try{
        invoke-AzureRemoteAppSessionLogoff -CollectionName rappaaeprod -UserUpn $userEmail -confirm:$false >$null 2>&1
        write-host "diconnected..." -ForegroundColor green
    }catch{
        $errorMessage = $_.Exception.Message
        if($errorMessage -eq "InternalError: The server encountered an internal error. Please retry the request."){
            write-host "User has been disconnected" -ForegroundColor green
        }else{
            write-host "ERROR: User connection to Azure not found" -ForegroundColor red
        }
    }
}

 

Example 1: this will prompt you for credentials then end the users session

end-azureSession Nathan.kewley@penrith.city

Example 2: You can save and pass credentials to the module

$cred = get-credential
end-azureSession Nathan.kewley@penrith.city $cred

 

 

Home