다윗의 제안, 나는 폴링을 만들어 결국 함수를 사용하여 상태 변경을 감지하고 내 주 스크립트로 다시보고하십시오.
먼저 DSC 작업을 성공적으로 감지하면 루프를 끝내야하는지,)
VM의 DSC 확장 프로그램에서 사용하는 파일에서 드릴 다운하여 가능한 상태 코드를 찾고 해당 조건을 기반으로합니다. 상태 코드는 DSC 확장이 설치된 가상 시스템의 C:\Packages\Plugins\Microsoft.Powershell.DSC\1.4.0.0\bin\DscExtensionStatus.psm1
에서 찾을 수 있습니다. 다음은 상태 코드는 DSC 확장 버전 1.4.0.0의과 같습니다
가
$DSC_Status = @{
Initializing = @{
Code = 1
Message = "Initializing DSC extension."
}
Completed = @{
Code = 2
Message = "DSC configuration was applied successfully."
}
Enabled = @{
Code = 3
Message = "PowerShell DSC has been enabled."
}
RebootingInstall = @{
Code = 4
Message = "Rebooting VM to complete installation."
}
RebootingDsc = @{
Code = 5
Message = "Rebooting VM to apply DSC configuration."
}
Applying = @{
Code = 6
Message = "Applying DSC configuration to VM."
}
#
# Errors
#
GenericError = 100; # The message for this error is provided by the specific exception
InstallError = @{
Code = 101
Message = "The DSC Extension was not installed correctly, please check the logs on the VM."
}
WtrInstallError = @{
Code = 102
Message = "WTR was not installed correctly, please check the logs on the VM."
}
}
기능의 논리는 마치 하나의 DSC 작업에서없는 즉, 상태 변화, 지속하기 때문에 다소 복잡하지만,에서 전체 확장 자체. 그 때문에 상태를 먼저 선택하여 업데이트를 찾으려고했습니다. timestamp
필드를 사용하여 새 상태를 감지했습니다. 여기에 코드입니다 :
function Wait-AzureDSCExtensionJob
{
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[string] $ServiceName,
[int] $RefreshIntervalSeconds = 15
)
Begin
{
$statusFormat = `
@{Label = 'Timestamp'; Expression = {$_.TimestampUtc}},
@{Label = 'Status'; Expression = {"$($_.Code) - $($_.Status)"}}, `
@{Label = 'Message'; Expression = {$_.FormattedMessage.Message}}
Write-Verbose 'Getting starting point status...'
$previousStatus = Get-AzureDscStatus -ServiceName:$ServiceName
Write-Verbose "Status obtained: $($previousStatus | Format-List $statusFormat | Out-String)"
Write-Verbose 'This status will be used as the starting point for discovering new updates.'
}
Process
{
do
{
Write-Verbose "Waiting for the next check cycle. $RefreshIntervalSeconds seconds left..."
Start-Sleep -Seconds:$RefreshIntervalSeconds
$currentStatus = Get-AzureDscStatus -ServiceName:$ServiceName
if ($previousStatus.TimestampUtc -eq $currentStatus.TimestampUtc)
{
Write-Verbose 'Status has not changed since the last check.'
$statusUpdated = $false
}
else
{
Write-Verbose "Status updated: $($currentStatus | Format-List $statusFormat | Out-String)"
$previousStatus = $currentStatus
$statusUpdated = $true
}
# Script with default message codes for the DSC Extension:
# On Target VM: "C:\Packages\Plugins\Microsoft.Powershell.DSC\1.4.0.0\bin\DscExtensionStatus.psm1"
} until ($statusUpdated -and (($currentStatus.Code -eq 2) -or ($currentStatus.Code -ge 100)))
}
End
{
switch ($currentStatus.Code)
{
2 {Write-Verbose 'Configuration finished successfully.'; break}
default {throw "Configuration failed: $($currentStatus.Status)"}
}
}
}
function Get-AzureDscStatus
{
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[string] $ServiceName
)
Begin
{
$vm = Get-AzureVM -ServiceName:$ServiceName
$dscExtensionStatus = $vm.ResourceExtensionStatusList | where { $_.HandlerName -eq 'Microsoft.PowerShell.DSC' }
if (-not $dscExtensionStatus)
{
throw 'Could not find the PowerShell DSC Extension on the VM'
}
$dscExtensionStatus.ExtensionSettingStatus
}
}
나는 아직 PowerShell을 매우 능숙하지 않다, 그래서 이것은 아마 조금 더보고 쉽게 읽을 수 있습니다. 아직도, 나는 그것이 나와 같은 상황에있는 누군가에게 유용 할 수 있기를 바란다.
UPDATE 28/11/2014는 :
Microsoft는 버전 1.5.0.0로 DSC 확장을 업데이트하고 내 기능은 그 얼마나 좋은 파산. 그들은 지금 코드를 교환하고 몇 가지 이유를 들어
$DSC_Status = @{
Success = @{
Code = 1
Message = 'DSC configuration was applied successfully.'
}
Initializing = @{
Code = 2
Message = 'Initializing DSC extension.'
}
Enabled = @{
Code = 3
Message = 'PowerShell DSC has been enabled.'
}
RebootingInstall = @{
Code = 4
Message = 'Rebooting VM to complete installation.'
}
RebootingDsc = @{
Code = 5
Message = 'Rebooting VM to apply DSC configuration.'
}
Applying = @{
Code = 6
Message = 'Applying DSC configuration to VM.'
}
#
# Errors
#
GenericError = 1000 # The message for this error is provided by the specific exception
InstallError = @{
Code = 1001
Message = 'The DSC Extension was not installed correctly, please check the logs on the VM.'
}
WtrInstallError = @{
Code = 1002
Message = 'WTR was not installed correctly, please check the logs on the VM.'
}
OsVersionNotSupported = @{
Code = 1003
Message = 'The current OS version is not supported. The DSC Extension requires Windows Server 2012 or 2012 R2, or Windows 8.1.'
}
}
: 여기
) 새로운 상태 코드입니다, 나는 응답 코드를 변경하면 같은 주요 변경 또는 아무것도 인 것처럼 그렇지 않은 의미 ... 1
은 성공했지만 오류는 100
에서 1000
으로 올라갔습니다 (그들은이 오류에 많은 오류가있을 것으로 예상합니다).
설명
의 상태를 얻기 위해 추가 한? http://technet.microsoft.com/en-us/library/dn249926.aspx 기본적으로 이벤트 로그를 사용하여 상태를 확인합니다 – Paul
@Paul 매우 흥미 롭습니다. VM에 대해이 명령을 실행해야한다고 생각합니다. 멀쩡해? Azure SDK를 사용하여 좀 더 자동화 된 것을 기대하고있었습니다. – julealgon
로컬로 호출 할 수도 있지만 기본적으로 예라고 할 수 있습니다. Azure SDK에 특별한 cmdlet이 있는지는 확실하지 않지만 의심 스럽습니다. – Paul