PowerShell Universal Dashboard: Ihr Azure-Leitfaden

Wenn Sie wissen, wie man PowerShell schreibt und ein grafisches Dashboard erstellen möchten, das praktisch alle Daten darstellt, schauen Sie sich PowerShell Universal Dashboard (UD) an. UD ist eine intuitive Möglichkeit, ansprechend aussehende Dashboards und sogar Formulare nur mit PowerShell zu erstellen. Glücklicherweise funktioniert Universal Powershell Dashboard auch in Azure!

Universal Powershell Dashboard ist ein PowerShell-Modul, das durch Ausführen von Install-Module -Name UniversalDashboard.Community installiert werden kann. Das Community-Modul ist kostenlos, aber ich empfehle Ihnen, die Vollversion zu erwerben.

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 benötigt einen Webserver zum Ausführen. Sie können sich dafür entscheiden, UD auf IIS oder in einer Azure Web App auszuführen. Ich mag es nicht, mich mit On-Premises-Infrastruktur herumzuschlagen, daher wähle ich immer die Bereitstellung von Ressourcen in der Cloud, wenn immer möglich. Da UD nativ das Ausführen in einer Azure Web App unterstützt, ist sie der perfekte Kandidat für die 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.

Es kann noch etwas verbessert werden, aber ich brauchte das nur für einen anstehenden Pluralsight Kurs, an dem ich gearbeitet habe. Fühlen Sie sich frei, es nach Bedarf zu verbessern. Hoffentlich erklären die Kommentare im Inneren alles ausreichend.

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

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

#region Erstellen Sie die Azure-Web-App
$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

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

# Holen Sie sich das Veröffentlichungsprofil für die Web-App
$pubProfile = Get-AzWebAppPublishingProfile -Name $Webappname -ResourceGroupName $AzureResourceGroup
$ftpPubProfile = ([xml]$pubProfile).publishData.publishProfile | Where-Object { $_.publishMethod -eq 'FTP' }

## Erstellen Sie die Berechtigung zum Authentifizieren
$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

	#region Erstellen Sie alle Ordner
	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

	## Erstellen Sie ein einfaches Dashboard, um die Website hochzufahren
	Set-Content -Path "$udModulePath\dashboard.ps1" -Value 'Start-UDDashboard -Wait'

	#region Laden Sie alle Dateien hoch
	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 {
	## Bereinigung
	$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'

Wenn Sie UD in Azure eingerichtet haben, ändern Sie die Datei dashboard.ps1, um jedes gewünschte Dashboard zu erstellen.

Öffnen Sie die URL Ihrer Azure-Web-App und erfreuen Sie sich an der frisch installierten Instanz des Universal PowerShell Dashboards.

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/