VMware Cloud Community
AlanR
Contributor
Contributor

Power CLI and remediate-inventory issues.

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.

Tags (2)
0 Kudos
5 Replies
LucD
Leadership
Leadership

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

0 Kudos
AlanR
Contributor
Contributor

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.

0 Kudos
RvdNieuwendijk
Leadership
Leadership

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

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
AlanR
Contributor
Contributor

Thanks, that looks to work, I will test some more, but I need to build a couple of hosts. Below is my completed  code segement to apply multiple baselines to a host.

Thank to all that enabled me to get this script working.

Code is posted below as an attachment.

0 Kudos
AlanR
Contributor
Contributor

Tested the script on new built host, and is working as desired, thanks again for the help on resolving this.

0 Kudos