PowerShell Universal Dashboard:您的 Azure 指南

如果您知道如何编写PowerShell并且需要构建代表几乎任何数据的图形仪表板,请查看PowerShell Universal Dashboard (UD)。UD是一种直观的方式,只使用PowerShell即可构建出外观精美的仪表板,甚至是表单。幸运的是,Universal Powershell Dashboard可以在Azure中使用!

Universal Powershell Dashboard是一个PowerShell模块,可以通过运行Install-Module -Name UniversalDashboard.Community来安装。社区模块是免费的,但我鼓励您购买完整版

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服务器来运行。您可以选择在IIS上运行UD,也可以在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 網頁應用程式
$appSrvPlan = New-AzAppServicePlan -Name "$WebAppName-AppSrv" -Location $AzureLocation -ResourceGroupName $AzureResourceGroup -Tier Free
$null = New-AzWebApp -Name $WebAppName -AppServicePlan $appSrvPlan.Name -ResourceGroupName $AzureResourceGroup -Location $AzureLocation
#結束區域

#區域 下載 UD
Save-Module UniversalDashboard.Community -Path $env:TEMP -AcceptLicense
$udModulePath = (Get-ChildItem -Path "$env:TEMP\UniversalDashboard.Community" -Directory).FullName
#結束區域

# 取得網頁應用程式的發行設定檔
$pubProfile = Get-AzWebAppPublishingProfile -Name $Webappname -ResourceGroupName $AzureResourceGroup
$ftpPubProfile = ([xml]$pubProfile).publishData.publishProfile | Where-Object { $_.publishMethod -eq 'FTP' }

## 建立認證的 cred
$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()
	}
	#結束區域

	## 建立簡單的儀表板來啟動網站
	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)
	}
	#結束區域
} 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'

當您在 Azure 中設定好 UD 後,您將修改 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/