VMware Cloud Community
eaphilipp
Contributor
Contributor
Jump to solution

Update vmware tools from .csv list

Hey Guys,

does this appear that it will work?

# Connect to vCenter #

Connect-VIServer -Server "vcenter" 

# Error Handling #

$ErrorActionPreference = "Continue"

# Source of VMs to be upgraded

$v = Get-Content "C:\vms.csv"

# Upgrades all VMs in vms.csv #

foreach ($v in $v) {

get-cluster -name "cluster1" | Get-VM $v | Where-Object {$_.PowerState -eq "PoweredOn"} | Update-Tools -NoReboot }

# Disconnects from vCenter #

disconnect-viserver -Confirm:$false

Thanks for the help as always!

-eric

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Depends how the content of your CSV file looks.

Is it is for example something like

"VMName"

"VM1"

"VM2"

You would need to use the following line (use the column name as the property)

Get-Cluster -name "cluster1" | Get-VM $v.VMName | Where-Object {$_.PowerState -eq "PoweredOn"} | Update-Tools -NoReboot }

For the rest the script looks fine.

You could eventually add the RunAsync switch to the Update-Tools cmdlet, the update will then run in the background.


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

View solution in original post

5 Replies
LucD
Leadership
Leadership
Jump to solution

Depends how the content of your CSV file looks.

Is it is for example something like

"VMName"

"VM1"

"VM2"

You would need to use the following line (use the column name as the property)

Get-Cluster -name "cluster1" | Get-VM $v.VMName | Where-Object {$_.PowerState -eq "PoweredOn"} | Update-Tools -NoReboot }

For the rest the script looks fine.

You could eventually add the RunAsync switch to the Update-Tools cmdlet, the update will then run in the background.


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

eaphilipp
Contributor
Contributor
Jump to solution

CSV file just has the names no header:

vm1

vm2

vm3

vm4

Seems to be working.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you sure VM1 got handled ?


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

Reply
0 Kudos
eaphilipp
Contributor
Contributor
Jump to solution

Yup, I watched the first VM in the list go through the process, it is a very slow but it is working.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

My mistake, I thought you were using Import-Csv, just noticed you're using Get-Content


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

Reply
0 Kudos