Within out environment we createbaslines based on requirements, and import these across a number of VC5 servers.
As part of our core build we want to ensure that the new host being built and auto added to VC, also gets patched to match other hosts inside the VC.
To this end I am trying to add the following to the core build PS script.
We currently have 3 Baseline bundles that must get applied to the ESXi5 servers.
Baseline-12-03-ESXi5.0-B01
Baseline-12-05-ESXi5.0-B02
Baseline-12-07-ESXi5.0-B03
See attachment for PS code.
With the code, all seems correct, but the remediate fails, with the following error.
Remediate-Inventory : Cannot bind parameter 'Baseline'. Cannot convert the "VMware.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBaselineImpl"
value of type "System.String" to type "VMware.VumAutomation.Types.Baseline".
Within out environment we createbaslines based on requirements, and import these across a number of VC5 servers.
As part of our core build we want to ensure that the new host being built and auto added to VC, also gets patched to match other hosts inside the VC.
To this end I am trying to add the following to the core build PS script.
We currently have 3 Baseline bundles that must get applied to the ESXi5 servers.
Baseline-12-03-ESXi5.0-B01
Baseline-12-05-ESXi5.0-B02
Baseline-12-07-ESXi5.0-B03
Remediate-Inventory : Cannot bind parameter 'Baseline'. Cannot convert the "VMware.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBaselineImpl"
value of type "System.String" to type "VMware.VumAutomation.Types.Baseline".
With the code, all seems correct, but the remediate fails, with the following error.
See attachment for PS code.
Try changing that last line of your script to
Remediate-Inventory -Entity (Get-VMHost $hosttarget) -Baseline "$basetoapply" -Confirm:$false
The Remediate-Inventory cmdlet requires an object for the Entity parameter.
It doesn't seem to do Object By Name (OBN) like several of the PowerCLI cmdlets do.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That helped, but I still cannot get the command to complete.
Orginal Code
{
$patch = Get-Baseline $missingbaselines[$i].baseline.name
if($basetoapply -eq "") { $basetoapply = $patch }
else{ $basetoapply = "$basetoapply, $patch"}
}
Remediate-Inventory-Entity $hosttarget -Baseline "$basetoapply" -Confirm:$false
error is now
Remediate-Inventory : Cannot bind parameter 'Baseline'. Cannot convert the "12-03-ESXi5.0, 12-07-ESXi5.0, VMware.VumAutomation.Types.PatchBaselineImpl, VMwar
e.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBa
selineImpl, VMware.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomat
ion.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBaselineImpl, VMware.VumAutomation.Types.PatchBaselineImpl"
value of type "System.String" to type "VMware.VumAutomation.Types.Baseline".
At C:\PS\patchhost.ps1:11 char:63
+ Remediate-Inventory -Entity (Get-VMhost $hosttarget) -Baseline <<<< "$basetoapply" #-Confirm:$false
+ CategoryInfo : InvalidArgument: (:) [Remediate-Inventory], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,VMware.VumAutomation.Commands.RemediateInventory
I tried moving the get-baseline command to 'pipe' into the remediate, but that also fails. See below
{
$patch = $missingbaselines[$i].baseline.name
if ($basetoapply -eq "") { $basetoapply = "$patch"}
else { $basetoapply = "$basetoapply, $patch"}
}
Get-Baseline -Name $basetoapply | Remediate-Inventory -Entity (Get-VMHost "$hosttarget")
this makes $basetoapply = 12-03-ESXi5.0, 12-05-ESXi5.0
error is now
Get-Baseline : 20/07/2012 11:07:01 Get-Baseline Could not find any baselines named '12-03-ESXi5.0, 12-05-ESXi5.0' on the server 'My VC Server'
If I place this on the commandline
Get-Baseline -Name 12-03-ESXi5.0, 12-07-ESXi5 | Remediate-Inventory -Entity (Get-VMHost "My ESX Host")
This command works, and it invokes VUM correctly.
The -Baseline parameter in the Remediate-Inventory cmdlet requires a baseline type object and not a string. I modified your script to create an array of baselines that should by applied:
$hosttarget = FQDN-of-target-host Get-Baseline -Name *ESXi5* | Attach-Baseline -Entity $hosttarget Scan-Inventory -Entity $hosttarget $missingbaselines = Get-Compliance -Entity $hosttarget | Where-Object { $_.status -ne "Compliant"} $basetoapply = @() for ($i = 0; $i -ilt $($missingbaselines.count); $i += 1) { $basetoapply += Get-Baseline $missingbaselines[$i].baseline.name } Remediate-Inventory -Entity (Get-VMHost $hosttarget) -Baseline $basetoapply -Confirm:$false
Regards, Robert
Tested the script on new built host, and is working as desired, thanks again for the help on resolving this.