Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Waits for a DSC configuration to complete on an Azure Virtual Machine.
function Wait-AzureVMDscConfiguration {
<#
.Synopsis
Waits for a DSC configuration to complete on an Azure Virtual Machine.
.Parameter ServiceName
The name of the Azure Cloud Service containing the Virtual Machine.
.Parameter Name
The name of the Azure Virtual Machine inside the Cloud Service container.
.Notes
Trevor Sullivan <pcgeek86@gmail.com>
http://trevorsullivan.net
http://twitter.com/pcgeek86
#>
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string] $ServiceName
,
[Parameter(Mandatory = $true)]
[string] $VMName
)
### This is the time that the function is initially called.
### We must wait for a status message that is newer than the current one (if it exists at all).
$StartTime = [DateTime]::UtcNow;
$DscResult = Get-AzureVMDscExtensionStatus -ServiceName $ServiceName -Name $VMName;
while ($DscResult.Status -notin @('Success', 'Warning', 'Error') -or ($DscResult.Timestamp.UtcDateTime -lt $StartTime)) {
Write-Verbose -Message ('Waiting for Azure VM DSC Extension to complete on {0}/{1}. Current state is: {2}.' -f $ServiceName, $VMName, $DscResult.Status);
Start-Sleep -Seconds 15;
$DscResult = Get-AzureVMDscExtensionStatus -ServiceName $ServiceName -Name $VMName;
}
Write-Verbose -Message ('{3}: Exiting function. Azure VM DSC state is {2} on {0}/{1} at {4}.' -f $ServiceName, $VMName, $DscResult.Status, $StartTime, $DscResult.Timestamp.UtcDateTime);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment