following code
function Get-SSMMaintenanceWindowMatch ($instance) {
$mws = (Get-SSMMaintenanceWindowList -Region eu-central-1).WindowId
for ($i=0; $i -le $mws.Length; $i++) {
$val = ((Get-SSMMaintenanceWindowTargets -region eu-central-1 -WindowId $mws[$i]).Targets).Values
if (($val -eq $instance) -and ($val -eq $null)) {
return $instance
else {
return -1
}
}
}
}
gives following error.
PS C:\WINDOWS\system32> Get-SSMMaintenanceWindowMatch $instanceId
Get-SSMMaintenanceWindowTargets : 1 validation error detected: Value null at 'windowId' failed to satisfy constraint: Member must not be
null
At line:4 char:18
+ ... $val = ((Get-SSMMaintenanceWindowTargets -region eu-central-1 -Win ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Amazon.PowerShe...owTargetsCmdlet:GetSSMMaintenanceWindowTargetsCmdlet) [Get-SSMMaintenan
ceWindowTargets], InvalidOperationException
+ FullyQualifiedErrorId : Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementException,Amazon.PowerShell.Cmdlets.SSM.GetSSMMa
intenanceWindowTargetsCmdlet
Some Maintenance Windows will not have a value since not targets (instances) are registered to them. In that momement a member of the array is null and the function doesnt work. If I use an instance that is registered directly it works.
How can I get the loop to work with just null members.
Thx for any input.