PowerShell Universal Dashboard: 당신의 Azure 안내서

다음은 PowerShell로 작성하는 방법을 알고 있고 거의 모든 데이터를 나타내는 그래픽 대시보드를 만들어야 할 경우에는 PowerShell Universal Dashboard (UD)를 확인해 보세요. UD는 PowerShell만을 사용하여 멋지게 보이는 대시보드와 심지어 양식을 만드는 직관적인 방법입니다. 다행히도, Universal Powershell 대시보드는 Azure에서 작동합니다!

Universal Powershell 대시보드는 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를 실행하기 위해 웹 서버가 필요합니다. UD를 실행할 수 있는 옵션으로는 IIS에서 실행하거나 Azure 웹 앱에서 실행할 수 있습니다. 온프레미스 인프라를 다루는 것을 싫어하기 때문에 가능한 경우 항상 클라우드로 리소스를 배포하는 것을 선호합니다. UD가 네이티브로 Azure 웹 앱에서 실행되도록 지원하기 때문에 이는 완벽한 클라우드 후보입니다.

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' }

##인증을 위한 자격 증명 작성
$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'

UD를 Azure에 설정한 후에는 dashboard.ps1 파일을 수정하여 필요한 모든 종류의 대시보드를 작성합니다.

Azure 웹 앱의 URL로 이동하여 새로 설치된 Universal Powershell 대시보드 인스턴스의 영광을 누려보세요.

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/