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
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
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
CSV file just has the names no header:
vm1
vm2
vm3
vm4
Seems to be working.
Are you sure VM1 got handled ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yup, I watched the first VM in the list go through the process, it is a very slow but it is working.
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