Azure
Learn how to host PowerShell Universal in Azure.
PowerShell Universal is an ASP.NET Core web application and can be hosted in Windows Azure Web Apps.

Manually Creating a Web App

Within the the Azure Portal, you will need to create a new Web App resource. PowerShell Universal currently requires the .NET 5 runtime stack. You can use either Linux or Windows.
In this example, we'll use the Azure PowerShell module to deploy the Web App manually.
You'll first need to install Azure PowerShell.
1
Install-Module Az
Copied!
Once installed, you'll need to connect to your subscription.
1
Connect-AzAccount
Copied!

Linux

There is a Known Issue with deploying PowerShell 2.5.x to Linux Web Apps.
Now, you can download the latest version of PowerShell Universal. In this example, we'll download the latest Linux version.
1
$LatestVersion = Invoke-RestMethod https://imsreleases.blob.core.windows.net/universal/production/version.txt
2
Invoke-WebRequest "https://imsreleases.blob.core.windows.net/universal/production/$LatestVersion/Universal.linux-x64.$LatestVersion.zip" -OutFile .\Universal.zip
Copied!
Now that we have the Az module configured and the Universal ZIP downloaded, we can deploy the Web App.
1
$Parameters = @{
2
Force = $true
3
ResourceGroupName = 'psu-demo'
4
Name = 'psudemo'
5
ArchivePath = '.\Universal.zip'
6
}
7
Publish-AzWebApp @Parameters
Copied!
After publishing the Web App, view your PowerShell Universal instance by navigating to the Web App's URL.

Windows

Now, you can download the latest version of PowerShell Universal. In this example, we'll download the latest Windows version.
1
$LatestVersion = Invoke-RestMethod https://imsreleases.blob.core.windows.net/universal/production/version.txt
2
Invoke-WebRequest "https://imsreleases.blob.core.windows.net/universal/production/$LatestVersion/Universal.win7-x64.$LatestVersion.zip" -OutFile .\Universal.zip
Copied!
Now that we have the Az module configured and the Universal ZIP downloaded, we can deploy the Web App.
1
$Parameters = @{
2
Force = $true
3
ResourceGroupName = 'psu-demo'
4
Name = 'psudemo'
5
ArchivePath = '.\Universal.zip'
6
}
7
Publish-AzWebApp @Parameters
Copied!
After publishing the Web App, view your PowerShell Universal instance by navigating to the Web App's URL.

Persistent Storage

The default appsettings.json file will store the database and configuration files in a non-persistent location. You can add environment variables to move them to persistent storage within your web app. Note the Data__ConnectionString and Data__RepositoryPath environment variables.

Updating your Web App

When a new version of PowerShell Universal is released, you will need to update the application files for your Web App. We recommend removing the application directory and redeploying the files. The database and configuration files are not stored in the application directory.
You can delete the files for your Web App by using the Kudu command API. Your Kudu credentials use Basic authentication and are the same as your deployment credentials.

Linux

To delete all the files in your Web App, issue the following command.
1
$Parameters = @{
2
Uri = "https://psudemo.scm.azurewebsites.net/api/command"
3
Credential = (Get-Credential)
4
Body = (@{
5
command = "rm -r /home/site/wwwroot"
6
dir = "/home/site/wwwroot"
7
} | ConvertTo-Json)
8
}
9
10
Invoke-RestMethod @Parameters
Copied!

Windows

To delete all the files in your Web App, issue the following command.
1
$Parameters = @{
2
Uri = "https://psudemo.scm.azurewebsites.net/api/command"
3
Credential = (Get-Credential)
4
Body = (@{
5
command = "rd /s /q D:\home\site\wwwroot"
6
dir = "D:\home\site\wwwroot"
7
} | ConvertTo-Json)
8
}
9
10
Invoke-RestMethod @Parameters
Copied!
Once you've delete the application files, you can redeploy them by running the manual creation steps again.

Setting Adjustments Required

JWT Signing Key

The default JWT signing key is not of a sufficient length and will need to be updated. This can be done in appsettings.json or by using environment variables.

appsettings.json

1
"Jwt": {
2
"SigningKey": "xXyt9UpJKB4Pb*4$hprd!JJoyOcK4ZOV**O7Hug9&@gYHcquot;,
3
"Issuer": "IronmanSoftware",
4
"Audience": "PowerShellUniversal"
5
},
Copied!

Environment Variable

1
$Env:Jwt__SigningKey = 'xXyt9UpJKB4Pb*4$hprd!JJoyOcK4ZOV**O7Hug9&@gYHc#x27;
Copied!

API URL

Azure Web Apps use a reverse proxy and PowerShell Universal does not detect the external URL appropriately. When running jobs, Universal uses the Management API to automatically look up job, script and schedule information. This means that this will fail if it cannot correctly address the external API URL.
The API URL should be the external HTTP address of your Web App. You can update this in appsettings.json or by using an environment variable.

appsettings.json

1
"Api": {
2
"Url": "https://psudemo.azurewebsites.net"
3
},
Copied!

Environment Variable

1
$Env:Api__Url = "https://psudemo.azurewebsites.net"
Copied!
Last modified 14d ago