Panel de control universal de PowerShell: Tu guía de Azure

Si sabes cómo escribir en PowerShell y necesitas construir un panel gráfico que represente prácticamente cualquier tipo de datos, echa un vistazo a PowerShell Universal Dashboard (UD). UD es una forma intuitiva de crear paneles con una apariencia estupenda e incluso formularios, todo utilizando solo PowerShell. Afortunadamente, Universal PowerShell Dashboard funciona en Azure!

Universal PowerShell Dashboard es un módulo de PowerShell que se puede instalar ejecutando Install-Module -Name UniversalDashboard.Community. El módulo comunitario es gratuito, pero te animo a que adquieras la versión completa.

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 necesita un servidor web para ejecutarse. Puedes optar por ejecutar UD en IIS o en una aplicación web de Azure. No me gusta lidiar con infraestructuras locales, así que siempre elijo implementar recursos en la nube siempre que puedo. Dado que UD admite nativamente la ejecución en una aplicación web de Azure, es el candidato perfecto para la nube.

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.

Puede necesitar algunos ajustes, pero yo solo lo necesitaba para un próximo curso de Pluralsight en el que estaba trabajando. Siéntete libre de mejorarlo según tus necesidades. Con suerte, los comentarios internos explicarán todo lo suficientemente bien.

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

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

#región Crear la aplicación web de 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

#región Descargar UD
Save-Module UniversalDashboard.Community -Path $env:TEMP -AcceptLicense
$udModulePath = (Get-ChildItem -Path "$env:TEMP\UniversalDashboard.Community" -Directory).FullName
#endregion

# Obtener el perfil de publicación para la aplicación web
$pubProfile = Get-AzWebAppPublishingProfile -Name $Webappname -ResourceGroupName $AzureResourceGroup
$ftpPubProfile = ([xml]$pubProfile).publishData.publishProfile | Where-Object { $_.publishMethod -eq 'FTP' }

## Construir la credencial para autenticar
$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

	#región Crear todas las carpetas
	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

	## Crear un panel de control simple para poner en marcha el sitio
	Set-Content -Path "$udModulePath\dashboard.ps1" -Value 'Start-UDDashboard -Wait'

	#región Subir todos los archivos
	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 {
	## Limpieza
	$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'

Una vez que haya configurado UD en Azure, modificará el archivo dashboard.ps1 para construir cualquier tipo de panel de control que necesite.

Acceda a la URL de su aplicación web de Azure y disfrute del esplendor de una instancia recién instalada 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/