I have created the PowerShell script for the renew registration key of the WVD host pool. And I have been uploaded the script to Azure Repo.
The script has been tested and it was work.
I have created the variable group already but I don't know how can apply them to the script.
My problem is how to change the script variable by the Azure DevOps Variable group?
Here is my PowerShell script renew_token.ps1 below:
$subscriptionID = "xxx-xxxx-xxx" $resourceGroupName = "rg-wvd" $hostPoolName = "hostpool-01" $Registered = Get-AzWvdRegistrationInfo -SubscriptionId "$subscriptionID" -ResourceGroupName "$resourceGroupName" -HostPoolName $hostPoolName $registrationTokenValidFor = "null" if (-not(-Not $Registered.Token)){$registrationTokenValidFor = (NEW-TIMESPAN -Start (get-date) -End $Registered.ExpirationTime | select Days,Hours,Minutes,Seconds)} Write-Host "Token is valid for:$registrationTokenValidFor" if ((-Not $Registered.Token) -or ($Registered.ExpirationTime -le (get-date))) { $Registered = New-AzWvdRegistrationInfo -SubscriptionId $subscriptionID -ResourceGroupName $resourceGroupName -HostPoolName $hostPoolName -ExpirationTime (Get-Date).AddHours(4) -ErrorAction SilentlyContinue $token = $Registered.Token $RdsRegistrationInfotoken = "Create new Token:$token" } Write-Host $RdsRegistrationInfotoken My Azure Pipeline:
trigger: - main variables: - group: Renew-Registration-Key pool: vmImage: windows-latest steps: - task: AzurePowerShell@5 inputs: azureSubscription: 'xxxxx-xxxxx-xxxx-xxxx' ScriptType: 'FilePath' ScriptPath: './renew_token.ps1' azurePowerShellVersion: 'LatestVersion' https://stackoverflow.com/questions/66451594/how-can-instead-of-the-variable-of-azure-devops-to-variable-of-powershell March 03, 2021 at 02:04PM
没有评论:
发表评论