PowerShell Universal Dashboard: Uw Azure Gids

Als je weet hoe je PowerShell moet schrijven en een grafisch dashboard wilt bouwen dat vrijwel alle gegevens vertegenwoordigt, bekijk dan PowerShell Universal Dashboard (UD). UD is een intuïtieve manier om aantrekkelijke dashboards en zelfs formulieren te maken met alleen PowerShell. Gelukkig werkt Universal Powershell Dashboard in Azure!

Universal Powershell Dashboard is een PowerShell-module die kan worden geïnstalleerd door Install-Module -Name UniversalDashboard.Community uit te voeren. De community-module is gratis, maar ik moedig je aan om de volledige versie aan te schaffen.

I’m not going to go into the ins and outs of UD, Adam Driscoll (UD’s developer) has written extensive documentation already on the topic.

UD heeft een webserver nodig om te kunnen draaien. Je kunt ervoor kiezen om UD op IIS te draaien of in een Azure Web App. Ik heb een hekel aan het rommelen met on-premises infrastructuur, dus ik kies er altijd voor om resources naar de cloud te implementeren wanneer dat kan. Aangezien UD van nature ondersteuning biedt voor uitvoering in een Azure Web App, is het de perfecte kandidaat voor de cloud.

I found that even though UD has docs for setting it up in Azure, I still was struggling with an easy way to get it going. I managed to come up with a rough PowerShell script to setup the latest instance for you all in one swoop.

Het kan wat werk vergen, maar ik had dit alleen nodig voor een aankomende Pluralsight-cursus waar ik aan werkte. Voel je vrij om het te verbeteren zoals je wilt. Hopelijk zullen de opmerkingen binnenin alles voldoende uitleggen.

param(
	[Parameter(Mandatory)]
	[ValidateNotNullOrEmpty()]
	[string]$WebAppName,
	
	[Parameter(Mandatory)]
	[ValidateNotNullOrEmpty()]
	[string]$AzureLocation,

	[Parameter(Mandatory)]
	[ValidateNotNullOrEmpty()]
	[string]$AzureResourceGroup
)

#regio Creëer de Azure-webtoepassing
$appSrvPlan = New-AzAppServicePlan -Name "$WebAppName-AppSrv" -Location $AzureLocation -ResourceGroupName $AzureResourceGroup -Tier Free
$null = New-AzWebApp -Name $WebAppName -AppServicePlan $appSrvPlan.Name -ResourceGroupName $AzureResourceGroup -Location $AzureLocation
#endregion

#regio Download UD
Save-Module UniversalDashboard.Community -Path $env:TEMP -AcceptLicense
$udModulePath = (Get-ChildItem -Path "$env:TEMP\UniversalDashboard.Community" -Directory).FullName
#endregion

# Haal het publicatieprofiel op voor de webtoepassing
$pubProfile = Get-AzWebAppPublishingProfile -Name $Webappname -ResourceGroupName $AzureResourceGroup
$ftpPubProfile = ([xml]$pubProfile).publishData.publishProfile | Where-Object { $_.publishMethod -eq 'FTP' }

## Bouw de cred om te authenticeren
$password = ConvertTo-SecureString $ftpPubProfile.userPWD -AsPlainText -Force
$azureCred = New-Object System.Management.Automation.PSCredential ($ftpPubProfile.userName, $password)

try {
	$webclient = New-Object -TypeName System.Net.WebClient
	$webclient.Credentials = $azureCred

	#regio Maak alle mappen aan
	Get-ChildItem -Path $udModulePath -Directory -Recurse | foreach {
		$path = $_.FullName.Replace("$udModulePath\", '').Replace('\', '/')
		$uri = "$($ftpPubProfile.publishUrl)/$path"
		$makeDirectory = [System.Net.WebRequest]::Create($uri)
		$makeDirectory.Credentials = $azureCred
		$makeDirectory.Method = [System.Net.WebRequestMethods+FTP]::MakeDirectory
		Write-Host "Creating folder [$path]..."
		$null = $makeDirectory.GetResponse()
	}
	#endregion

	## Maak een eenvoudig dashboard om de site te starten
	Set-Content -Path "$udModulePath\dashboard.ps1" -Value 'Start-UDDashboard -Wait'

	#regio Upload alle bestanden
	Get-ChildItem -Path $udModulePath -File -Recurse | foreach {
		$path = $_.FullName.Replace("$udModulePath\", '').Replace('\', '/').Replace('.\', '')
		$uri = New-Object System.Uri("$($ftpPubProfile.publishUrl)/$path")
		Write-Host "Uploading file [$path]..."
		$null = $webclient.UploadFile($uri, $_.FullName)
	}
	#endregion
} catch {
	$PSCmdlet.ThrowTerminatingError($_)
} finally {
	## Opschonen
	$webclient.Dispose()
}

I called the script New-UDAzureInstance.ps1 and launch it like:

PS> ./New-UDAzureInstance.ps1 -WebAppName ADBPoshUD -AzureResourceGroup 'Course-PowerShellDevOpsPlaybook' -AzureLocation 'East US'

Zodra je UD hebt ingesteld in Azure, pas je vervolgens het dashboard.ps1 bestand aan om elk soort dashboard te bouwen dat je nodig hebt.

Blader naar de URL van je Azure-webtoepassing en geniet van de glorie van een zojuist geïnstalleerde Universal Powershell Dashboard-instantie.

PowerShell Universal Dashboard in Azure

I hope this saves some people some time setting up Universal Powershell Dashboard in Azure!

Source:
https://adamtheautomator.com/powershell-universal-dashboard/