لوحة التحكم الشاملة لـ PowerShell: دليلك لـ 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 بحاجة إلى خادم ويب للتشغيل. يمكنك اختيار تشغيل 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
#endregion

#منطقة تنزيل UD
Save-Module UniversalDashboard.Community -Path $env:TEMP -AcceptLicense
$udModulePath = (Get-ChildItem -Path "$env:TEMP\UniversalDashboard.Community" -Directory).FullName
#endregion

# الحصول على ملف تكوين النشر لتطبيق الويب
$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 لبناء أي نوع من لوحات التحكم التي تحتاج إليها.

انتقل إلى عنوان URL لتطبيق الويب في Azure الخاص بك واستمتع بجاهزية نسخة جديدة من لوحة تحكم 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/