Tableau de bord universel PowerShell : Votre guide Azure

Si vous savez comment écrire PowerShell et avez besoin de construire un tableau de bord graphique représentant presque n’importe quelle donnée, consultez le PowerShell Universal Dashboard (UD). UD est un moyen intuitif de créer des tableaux de bord attrayants et même des formulaires en utilisant uniquement PowerShell. Heureusement, Universal Powershell Dashboard fonctionne dans Azure !

Universal Powershell Dashboard est un module PowerShell disponible en installant Install-Module -Name UniversalDashboard.Community. Le module communautaire est gratuit, mais je vous encourage à acheter la version complète.

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 a besoin d’un serveur web pour fonctionner. Vous pouvez choisir d’exécuter UD sur IIS ou dans une application web Azure. Je déteste manipuler l’infrastructure sur site, donc je choisis toujours de déployer des ressources dans le cloud chaque fois que je le peux. Étant donné que UD prend en charge nativement l’exécution dans une application web Azure, c’est le candidat idéal pour le cloud.

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.

Il peut être amélioré, mais j’avais juste besoin de cela pour un prochain cours Pluralsight sur lequel je travaillais. N’hésitez pas à l’améliorer selon vos besoins. J’espère que les commentaires à l’intérieur expliqueront tout suffisamment bien.

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

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

#region Créer l'application web 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 Télécharger UD
Save-Module UniversalDashboard.Community -Path $env:TEMP -AcceptLicense
$udModulePath = (Get-ChildItem -Path "$env:TEMP\UniversalDashboard.Community" -Directory).FullName
#endregion

# Obtenir le profil de publication pour l'application web
$pubProfile = Get-AzWebAppPublishingProfile -Name $Webappname -ResourceGroupName $AzureResourceGroup
$ftpPubProfile = ([xml]$pubProfile).publishData.publishProfile | Where-Object { $_.publishMethod -eq 'FTP' }

## Construire les informations d'identification pour l'authentification
$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 Créer tous les dossiers
	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

	## Créer un tableau de bord simple pour mettre en place le site
	Set-Content -Path "$udModulePath\dashboard.ps1" -Value 'Start-UDDashboard -Wait'

	#region Télécharger tous les fichiers
	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 {
	## Nettoyer
	$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'

Une fois que vous avez configuré UD dans Azure, vous modifierez ensuite le fichier dashboard.ps1 pour créer n’importe quel type de tableau de bord dont vous avez besoin.

Accédez à l’URL de votre application web Azure et profitez de la gloire d’une instance fraîchement installée de 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/