Welcome to the Inedo Forums! Check out the Forums Guide for help getting started.
If you are experiencing any issues with the forum software, please visit the Contact Form on our website and let us know!
PSEnsure using Map Expression (Hash Table)
-
Hello,
I am using a PSensure to collect the information. I have a map expression configured on the server variable as to to check for disk labels:
%DiskLabel %(C: OSDisk, D: DataDisk1)And this runs in a role to collect for each server it is assigned to:
##AH:UseTextMode## Ensure Disk Label configuration PSEnsure ( Key: Disk Label Check, Value: True, Collect: >> $ServerVariable = $DiskLabel $Disks = Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" $ServerVariable.GetEnumerator() |ForEach-Object { if ( ($Disks.DeviceID).Replace(':','') -contains ("$($_.Key)")) { $y = $disks | Where-Object -Property DeviceID -match $_.Key; $y.VolumeName -eq $($_.Value) }} >>, Configure: >> write-output "The fix is in" >> );
But when it collects, even though the values are both true, it reports as drift. Ideas?
Product: Otter
Version: 2.0.10
-
What is the output of your log?
I think this will always report drift, because in all cases your Collect script will return an array of unknown length (number od drives), where as your Value is always a scalar (true).
-
The output is the following:
ServerCheckout_DiskLabelCheck
Ensure $ServerVariable = $DiskLabel $Disks = Get-WmiObject -Class Win3 using PowerShell
DEBUG: Collecting configuration...
DEBUG: Importing DiskLabel...
DEBUG: Comparing configuration...
DEBUG: Difference: Value
DEBUG: =Template=> True
DEBUG: = Actual => True, True
INFO: Configuration drift detected.
DEBUG: Adding to execution plan.
-
Yes, you can see that the values aren't the same, so there's drift. "True" is not "True, True".
You'll need to change your PS to only return a scalar/Boolean (i.e. "True"), not an array of values.
-
Since I wanted all of my values in the array to be true to have success in my PSEnsure I thought of different ways I could do this. I settled on counting the items in the array, and using the fact that $true -eq 1 and $false -eq 0 to build a value that should match the count. I added this to the end:
$array.ForEach({if ($) {$val += $}})
$array.Count -eq $val
Thanks for your help!