Hello PowerShell experts!
I hope someone can help with the below.
I am creating a Scale Set in Azure and using DSC to configure the VMs. The scale set (of 50 VMs) is created once a week for about 12hrs and then discarded at the end of the day.
The DSC Configuration File has been successful for the past 5 or 6 months without any glitches until recently when the Scale Set provisioning failed.
Looking at the error from Azure, it is related to DSC.
Looking at the DSC log file:
VERBOSE: [2018-12-03 00:18:36Z] [VERBOSE] [Feb201800053Z]: LCM: [ Start
Resource ] [[xScript]Reboot]
VERBOSE: [2018-12-03 00:18:36Z] [VERBOSE] [Feb201800053Z]: LCM: [ Start Test
] [[xScript]Reboot]
VERBOSE: [2018-12-03 00:18:36Z] [VERBOSE] [Feb201800053Z]:
[[xScript]Reboot] Begin executing test script.
VERBOSE: [2018-12-03 00:18:36Z] [VERBOSE] [Feb201800053Z]:
[[xScript]Reboot] Executing script:
If (Get-eventlog system -After (get-date).Date -Source
‘User32’ ) {
Return $true
} Else {
Return $false
}
VERBOSE: [2018-12-03 00:18:36Z] [VERBOSE] [Feb201800053Z]: LCM: [ End Test
] [[xScript]Reboot] in 0.3590 seconds.
VERBOSE: [2018-12-03 00:18:36Z] [ERROR] PowerShell DSC resource
MSFT_xScriptResource failed to execute Test-TargetResource functionality with
error message: System.InvalidOperationException: The test script threw an
error. —> System.ArgumentException: No matches found
— End of inner exception stack trace —
VERBOSE: [2018-12-03 00:18:36Z] [VERBOSE] [Feb201800053Z]: LCM: [ End Set
]
The DSC configuration file section is configured as below:
xScript Reboot
{
SetScript = {
Restart-Computer -force
}
TestScript = {
If (Get-eventlog system -After (get-date).Date -Source ‘User32’ ) {
Return $true
} Else {
Return $false
}
}
GetScript = { }
DependsOn = “[xScript]ConfigPlexos”
PsDscRunAsCredential = $Credential
}
Essentially what it is supposed to do is check if the VM has rebooted after installing a package (denoted here by the line DependsOn) . If it hasn’t, then it restarts.
I was able to fix this issue by adding -ErrorAction Silently Continue on the IF statement.
The question I have is ‘Why!?’
The if statement checks if there is an event in the System log where the source is User32. If there is, the TestScript should return $true. If there isn’t, then the TestScript should return $false. It worked fine for 5 or 6 months… Why is it now spitting an error ‘No Matches Found’? It shouldn’t spit out an error but should rather spit out $false shouldn’t it??
Thank you in advance for your help and efforts.
Karim