VMware Cloud Community
BobFriend
Contributor
Contributor

Need help with patching via powercli

I am attempting to create a script for our L1 folks to run against individual clusters. In an attempt to make it as easy as possible on them I am trying to set it up so they just have to change 3 variables each time they run it to target the intended cluster.  I have included my script below. I am running into problems when I try to use $baseline. When using it I get the error below. The baseline exists as I am able to reference it directly using Get-Baseline -name "baseline name"

Get-Baseline Could not find any baselines named 'VMware.VumAutomation.Types.PatchBaselineImpl' on the server

### Variables ###

$cluster = Get-Cluster -Name "VUM Test Cluster"

$vmhosts = Get-VMHost -Name (get-content "c:\Temp\vmhosts.txt")

$baseline = Get-Baseline -Name "Test-PowerCLI" 

### Disabling HA on the Cluster.  ###

Set-Cluster -Cluster $cluster -HAEnabled:$false -Confirm:$false

foreach ($vmhost in $vmhosts) {

get-vmhost -Name $vmhost | Set-VMHost -State Maintenance -Confirm:$false

Get-Baseline -Name $baseline | Attach-Baseline -entity $vmhost -Confirm:$false

Scan-Inventory -Entity $vmhost

get-baseline -name $baseline | Remediate-Inventory -Entity $vmhost -Confirm:$false -erroraction Silentlycontinue

get-vmhost -name $vmhost | set-vmhost -state Connected -Confirm:$false

}

### Enabling HA on the Cluster.  ###

Set-Cluster -Cluster $cluster -HAEnabled:$true -Confirm:$false

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

Looks like you are doing Get-Baseline twice.

First in $baseline = Get-Baseline -Name "Test-PowerCLI"

And then you use the baseline object on the Name parameter in Get-Baseline -Name $baseline


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
BobFriend
Contributor
Contributor

So I can't use Get-Baseline in the same manner I am using Get-VMhost?

Reply
0 Kudos
LucD
Leadership
Leadership

No, and in fact neither should you do that for Get-VMHost.

The Name parameter expects a [string], not an object.

With Get-VMHost you get away with that since it is able to extract the name from the object, with Get-Baseline you get an error.

Best practice is to use a [string] where a [string] is due.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos