Created
May 22, 2015 19:30
-
-
Save pcgeek86/f837d528d90152ba1abc to your computer and use it in GitHub Desktop.
Waits for a DSC configuration to complete on an Azure Virtual Machine.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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