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 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
)

#region יצירת אפליקציית האינטרנט ב-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

#region הורדת 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

	#region יצירת כל התיקיות
	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'

	#region העלאת כל הקבצים
	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 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/