PowerShell Universal Dashboard:Azureガイド

PowerShellを書く方法を知っており、ほぼすべてのデータを表すグラフィカルなダッシュボードを作成する必要がある場合は、PowerShell Universal Dashboard (UD)をチェックしてみてください。UDは、PowerShellだけで見栄えの良いダッシュボードやフォームを簡単に作成する直感的な方法です。幸運なことに、Universal Powershell DashboardはAzureで動作します!

Universal Powershell Dashboardは、Install-Module -Name UniversalDashboard.Communityを実行してインストールできるPowerShellモジュールです。コミュニティモジュールは無料ですが、フルバージョンの購入をお勧めします。

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は、実行するためにWebサーバーが必要です。UDをIIS上またはAzure Web Appで実行することを選択できます。オンプレミスインフラストラクチャを扱うのは面倒なので、できる限りクラウドにリソースを展開することを常に選択しています。UDはAzure Web Appでネイティブに実行できるため、完璧なクラウド候補です。

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.

まだ改良の余地がありますが、私はこれを私が取り組んでいる予定のPluralsightのコースに必要だったので、それで十分です。必要に応じて改善してください。内部のコメントがすべてを説明してくれるはずです。

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

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

#Azure Webアプリを作成する
$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

#UDをダウンロードする
Save-Module UniversalDashboard.Community -Path $env:TEMP -AcceptLicense
$udModulePath = (Get-ChildItem -Path "$env:TEMP\UniversalDashboard.Community" -Directory).FullName
#endregion

#Webアプリのパブリッシングプロファイルを取得する
$pubProfile = Get-AzWebAppPublishingProfile -Name $Webappname -ResourceGroupName $AzureResourceGroup
$ftpPubProfile = ([xml]$pubProfile).publishData.publishProfile | Where-Object { $_.publishMethod -eq 'FTP' }

##認証のための資格情報を構築する
$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

	#すべてのフォルダを作成する
	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

	##必要なダッシュボードを作成する
	Set-Content -Path "$udModulePath\dashboard.ps1" -Value 'Start-UDDashboard -Wait'

	#すべてのファイルをアップロードする
	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 {
	##クリーンアップ
	$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'

UDがAzureに設定されたら、dashboard.ps1ファイルを変更して必要なダッシュボードを作成します。

Azure Web AppのURLにアクセスし、新しくインストールされたUniversal Powershell Dashboardインスタンスの栄光を堪能してください。

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/