Pages: [1]
Print
Author Topic: update-tools  (Read 236 times)
KristianW
Newbie
*
Posts: 17


View Profile
« on: August 28, 2010, 05:19:18 PM »

After vmware added the update-tools cmdlet, I am trying to figure out some things. Since my old script does not work, I have to discover the wheel again......

1. How do you list VMs which are powered on AND have toolsstatus "Out of date"
2. My new script tells me that one of my variables are empty..

Code:
$servers= get-cluster -Name <clustername> | get-vm
foreach ($VM in $servers)

update-tools $VM

Error message is that $VM cannot be <null>

I found one script that I hoped I could fix to suit my needs, but I am not capable of tweaking it to my needs.

Code:
$starttime = get-date
#requires -version 2
$OldTools = Get-View -ViewType “VirtualMachine” `
-Property Guest,name `
-filter @{
“Guest.GuestFamily”=”windowsGuest”;
“Guest.ToolsStatus”=”ToolsOld”;
“Guest.GuestState”=”running”
}

Foreach ($VM in $OldTools) {
Get-VM `
| Get-View | Where-Object { ($_.Guest.GuestFamily -eq “windowsGuest”)
-and ( $_.Guest.GuestState -eq “running” ) -and ( $_.Guest.ToolsStatus
-eq “ToolsOld” ) } | Get-VIObjectByVIView | Update-Tools -NoReboot
}
$processed = $oldTools.count – (Get-View -ViewType “VirtualMachine” `
-Property Guest,name `
-filter @{
“Guest.GuestFamily”=”windowsGuest”;
“Guest.ToolsStatus”=”ToolsOld”;
“Guest.GuestState”=”running”
}).count
$ts = New-TimeSpan -Start $starttime
write-host (“{0} out of {1} vm’s were updated in {2}.{3} Min” -f
$processed, $oldTools.count, $ts.Minutes,$ts.Seconds)

I need it to give me the possibility to choose cluster since I have 4 clusters (two that I cannot upgrade and the two others I have to take seperately). I tried adding some cluster specific code, but it just gave me an error saying that "-property" was not recognized (or something)

Anyone out there that could help?
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 247


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #1 on: August 29, 2010, 10:03:27 AM »

Before the get-vm under the Foreach statement... you can add the get-cluster | statement

Code:

$starttime = get-date
#requires -version 2
$OldTools = Get-View -ViewType “VirtualMachine” `
-Property Guest,name `
-filter @{
“Guest.GuestFamily”=”windowsGuest”;
“Guest.ToolsStatus”=”ToolsOld”;
“Guest.GuestState”=”running”
}

Foreach ($VM in $OldTools) {
Get-Cluster "Clustername" | Get-VM `
| Get-View | Where-Object { ($_.Guest.GuestFamily -eq “windowsGuest”)
-and ( $_.Guest.GuestState -eq “running” ) -and ( $_.Guest.ToolsStatus
-eq “ToolsOld” ) } | Get-VIObjectByVIView | Update-Tools -NoReboot
}
$processed = $oldTools.count – (Get-View -ViewType “VirtualMachine” `
-Property Guest,name `
-filter @{
“Guest.GuestFamily”=”windowsGuest”;
“Guest.ToolsStatus”=”ToolsOld”;
“Guest.GuestState”=”running”
}).count
$ts = New-TimeSpan -Start $starttime
write-host (“{0} out of {1} vm’s were updated in {2}.{3} Min” -f
$processed, $oldTools.count, $ts.Minutes,$ts.Seconds)
Logged
KristianW
Newbie
*
Posts: 17


View Profile
« Reply #2 on: August 30, 2010, 05:21:14 AM »

I tried that, but it did not work properly.... I have to take another look at it Smiley

Thanks!
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 247


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #3 on: August 30, 2010, 10:03:25 AM »

what did it not do?
Logged
KristianW
Newbie
*
Posts: 17


View Profile
« Reply #4 on: August 31, 2010, 04:58:19 AM »

what did it not do?

Sorry, I saw wrong... I thought the "get-cluster" was put earlier in the script.

This might work better Smiley

Giving it a go.
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 247


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #5 on: August 31, 2010, 08:15:39 AM »

great, let me know
Logged
Pages: [1]
Print
Jump to: