# Looks for Non-Windows VMs with Old Tools
# Requirements: Powershell Version 2.0, PowerCLI 4.01 (not 4.0)
# Version 1.0 - 6/28/2011
######################################
# Prompt to specify vCenter & Cluster
######################################
$vCenterName = Read-Host "Which vCenter to connect to (FQDN)"
$clusterName = Read-Host "Which Cluster"
##############################
# Connect to specified vCenter
##############################
Connect-VIServer -server $vCenterName -Protocol https -User "Username" -Password "Password"
##############################
# Get collection of VMs, create log file
##############################
$colVMs = get-cluster -name $clusterName | Get-VM
$logFile = New-Item -ItemType File -Path "d:\scripts\ScriptOutput\LinuxVMs-oldTools_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).log"
$linuxVMs = "d:\scripts\ScriptOutput\LinuxVMs-oldTools_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).csv"
##############################
# Get variables for each VM
##############################
foreach ($VM in $colVMs) {
$VMPower = $VM.PowerState
$VMName = $VM.name
$OS = (Get-VMGuest $VM).OSFullName
$vmID = get-vm $VM | foreach {get-view $_.Id}
$vmToolsStatus = $vmID.Guest.ToolsStatus
If ($OS -notlike "*Windows*") {
# Formatting the output
$output = New-Object PSObject
$output | Add-Member -MemberType NoteProperty -name Name -value $VMName
$output | Add-Member -MemberType NoteProperty -name NoToolsStatus -value $vmToolsStatus
$output | Add-Member -MemberType NoteProperty -name OperatingSystem -value $OS
$output | Add-Member -MemberType NoteProperty -name Cluster -value $clusterName
Write-Output $output | Export-Csv $LinuxVMs -noType -Append
Write-Host $VMName `t $vmToolsStatus `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`t`t`t" + $vmToolsStatus + "`t`t`t`t" + $OS)
}
else {
Write-Host $VMName `t $vmToolsStatus `t $OS -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`t`t`t" + $vmToolsStatus + "`t`t`t`t" + $OS)
}
}
##############################
# Disconnect from vCenter
##############################
Disconnect-VIServer -server $global:DefaultVIServers -Force
##############################
# Email log file
##############################
#send-mailmessage -SmtpServer "SMTPServerName" `
#-from "VM-Tools-Upgrade <DoNotReply@noreply.gov>" `
#-to "Somebody <somebody@somewhere.gov>" `
#-subject "VMware Tools Upgrade" `
#-body "VMware Tools upgrade log attached." `
#-Attachment $logFile
##############################
No comments:
Post a Comment