For ESXi hosts :
/usr/bin/vim-cmd vmsvc/getallvms
That will return a list of all vms running on the host in the format:
VMID VM Name Datastore Folder/VMX VM "type"
2256 VM [datastore name] VM/VM.vmx winNetStandard64Guest vmx-04
Note the Vmid of the VM with the stuck install and then use the second command as indicated:
/usr/bin/vim-cmd vmsvc/tools.cancelinstall VMID (in this example 2256)
For ESXfatclassy hosts:
/usr/bin/vmware-cmd /vmfs/volumes/whatever-datastore-name/vm-folder/vmx-file.vmx getid
/usr/bin/vmware-vim-cmd vmsvc/tools.cancelinstall vmidnumber
Tuesday, July 19, 2011
Tuesday, July 12, 2011
Enable Hot Add Mem & vCPU
<#
# Search for "Hot Add" Capable VMs and Enable
# Requirements: Powershell Version 2.0, PowerCLI 4.01 (not 4.0)
# Version 1.0 - 7/12/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\HotAddCapableVMsList_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).log"
#################################################################
# Enable / Disable Hot Add Functions
#################################################################
Function Enable-vCpuAndMemHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra1 = New-Object VMware.Vim.optionvalue
$extra1.Key="mem.hotadd"
$extra1.Value="true"
$vmConfigSpec.extraconfig += $extra1
$extra2 = New-Object VMware.Vim.optionvalue
$extra2.Key="vcpu.hotadd"
$extra2.Value="true"
$vmConfigSpec.extraconfig += $extra2
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
Function Enable-MemHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="mem.hotadd"
$extra.Value="true"
$vmConfigSpec.extraconfig += $extra
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
Function Disable-MemHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="mem.hotadd"
$extra.Value="false"
$vmConfigSpec.extraconfig += $extra
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
Function Enable-vCpuHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="vcpu.hotadd"
$extra.Value="true"
$vmConfigSpec.extraconfig += $extra
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
Function Disable-vCpuHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="vcpu.hotadd"
$extra.Value="false"
$vmConfigSpec.extraconfig += $extra
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
#################################################################
#
#################################################################
foreach ($VM in $colVMs) {
$VMPower = $VM.PowerState
$VMName = $VM.name
$OS = (Get-VMGuest $VM).OSFullName
$vHW = $vm.ExtensionData.Config.Version
##############################
# See if VM is powered on
##############################
if ($VMPower -notmatch "PoweredON") {
Write-Host $VMName `t "Powered OFF" -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`tNo Update`t`tPowered OFF")
}
##############################
# See if VM is vHW 7
##############################
elseif ($vHW -notmatch "vmx-07") {
Write-Host $VMName `t "Not vHW 7" -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`tNo Update`t`tNot vHW 7`t`t" + $vHW)
}
###############################
# See if VM has a Windows 7
###############################
elseif ($OS -like "*Windows 7*"){
Enable-vCpuAndMemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###############################
# See if VM has a Windows 2008
###############################
elseif ($OS -like "*Windows Server 2008*"){
Enable-vCpuAndMemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# See if VM has a Windows 2003 Ent
###################################
elseif ($OS -like "*Windows Server 2003,Enterprise Edition*"){
Enable-MemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# See if VM has a SLES 11
###################################
elseif ($OS -like "Suse Linux Enterprise 11*"){
Enable-vCpuAndMemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# See if VM has a SLES 10
###################################
elseif ($OS -like "Suse Linux Enterprise 10*"){
Enable-MemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# See if VM has a RHEL 5 (64-bit)
###################################
elseif ($OS -like "Red Hat Enterprise Linux 5 (64-bit)"){
Enable-vCpuAndMemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# Everything Else
###################################
else {
Write-Host $VMName `t $OS -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`tNo Update`t`t" + $OS + "`t`t" + $vHW)
}
}
##############################
# 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
##############################
# Search for "Hot Add" Capable VMs and Enable
# Requirements: Powershell Version 2.0, PowerCLI 4.01 (not 4.0)
# Version 1.0 - 7/12/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\HotAddCapableVMsList_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).log"
#################################################################
# Enable / Disable Hot Add Functions
#################################################################
Function Enable-vCpuAndMemHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra1 = New-Object VMware.Vim.optionvalue
$extra1.Key="mem.hotadd"
$extra1.Value="true"
$vmConfigSpec.extraconfig += $extra1
$extra2 = New-Object VMware.Vim.optionvalue
$extra2.Key="vcpu.hotadd"
$extra2.Value="true"
$vmConfigSpec.extraconfig += $extra2
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
Function Enable-MemHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="mem.hotadd"
$extra.Value="true"
$vmConfigSpec.extraconfig += $extra
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
Function Disable-MemHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="mem.hotadd"
$extra.Value="false"
$vmConfigSpec.extraconfig += $extra
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
Function Enable-vCpuHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="vcpu.hotadd"
$extra.Value="true"
$vmConfigSpec.extraconfig += $extra
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
Function Disable-vCpuHotAdd($vm){
$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
$extra = New-Object VMware.Vim.optionvalue
$extra.Key="vcpu.hotadd"
$extra.Value="false"
$vmConfigSpec.extraconfig += $extra
$vm.Extensiondata.ReconfigVM($vmConfigSpec)
}
#################################################################
#
#################################################################
foreach ($VM in $colVMs) {
$VMPower = $VM.PowerState
$VMName = $VM.name
$OS = (Get-VMGuest $VM).OSFullName
$vHW = $vm.ExtensionData.Config.Version
##############################
# See if VM is powered on
##############################
if ($VMPower -notmatch "PoweredON") {
Write-Host $VMName `t "Powered OFF" -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`tNo Update`t`tPowered OFF")
}
##############################
# See if VM is vHW 7
##############################
elseif ($vHW -notmatch "vmx-07") {
Write-Host $VMName `t "Not vHW 7" -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`tNo Update`t`tNot vHW 7`t`t" + $vHW)
}
###############################
# See if VM has a Windows 7
###############################
elseif ($OS -like "*Windows 7*"){
Enable-vCpuAndMemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###############################
# See if VM has a Windows 2008
###############################
elseif ($OS -like "*Windows Server 2008*"){
Enable-vCpuAndMemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# See if VM has a Windows 2003 Ent
###################################
elseif ($OS -like "*Windows Server 2003,Enterprise Edition*"){
Enable-MemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# See if VM has a SLES 11
###################################
elseif ($OS -like "Suse Linux Enterprise 11*"){
Enable-vCpuAndMemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# See if VM has a SLES 10
###################################
elseif ($OS -like "Suse Linux Enterprise 10*"){
Enable-MemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# See if VM has a RHEL 5 (64-bit)
###################################
elseif ($OS -like "Red Hat Enterprise Linux 5 (64-bit)"){
Enable-vCpuAndMemHotAdd $vm
Write-Host $VMName `t $OS -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tUpdate Hot Add`t`t" + $OS + "`t`t" + $vHW)
}
###################################
# Everything Else
###################################
else {
Write-Host $VMName `t $OS -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`tNo Update`t`t" + $OS + "`t`t" + $vHW)
}
}
##############################
# 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
##############################
Tuesday, July 5, 2011
FindRDMS.ps1
######################################
# 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"
$logFile = New-Item -ItemType File -Path "D:\scripts\ScriptOutput\VMware-RDMS-_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).log"
$vms = get-cluster -name $clusterName | Get-VM | Get-View
foreach($vm in $vms){
foreach($dev in $vm.Config.Hardware.Device){
if(($dev.gettype()).Name -eq "VirtualDisk"){
if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or
($dev.Backing.CompatibilityMode -eq "virtualMode")){
Add-Content -Path $logFile -Value ("________________________________________")
Add-Content -Path $logFile -Value ($vm.Name)
Add-Content -Path $logFile -Value ((Get-View $vm.Runtime.Host).Name)
Add-Content -Path $logFile -Value ($dev.Backing.DeviceName)
Add-Content -Path $logFile -Value ($dev.Backing.FileName)
Add-Content -Path $logFile -Value ($dev.Backing.CompatibilityMode)
Add-Content -Path $logFile -Value ($dev.CapacityInKB)
Add-Content -Path $logFile -Value ("________________________________________")
}
}
}
}
##############################
# 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
##############################
# 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"
$logFile = New-Item -ItemType File -Path "D:\scripts\ScriptOutput\VMware-RDMS-_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).log"
$vms = get-cluster -name $clusterName | Get-VM | Get-View
foreach($vm in $vms){
foreach($dev in $vm.Config.Hardware.Device){
if(($dev.gettype()).Name -eq "VirtualDisk"){
if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or
($dev.Backing.CompatibilityMode -eq "virtualMode")){
Add-Content -Path $logFile -Value ("________________________________________")
Add-Content -Path $logFile -Value ($vm.Name)
Add-Content -Path $logFile -Value ((Get-View $vm.Runtime.Host).Name)
Add-Content -Path $logFile -Value ($dev.Backing.DeviceName)
Add-Content -Path $logFile -Value ($dev.Backing.FileName)
Add-Content -Path $logFile -Value ($dev.Backing.CompatibilityMode)
Add-Content -Path $logFile -Value ($dev.CapacityInKB)
Add-Content -Path $logFile -Value ("________________________________________")
}
}
}
}
##############################
# 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
##############################
windowsServer-Info.ps1
#get list of hosts
$hosts=get-content "h:\scripts\hosts.txt"
$P2VCandidates="h:\scripts\ScriptOutput\P2VCandidatesOutput_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).csv"
$tableInfo=@("DeviceId", "VolumeName", @{Label="FreeSpace(GB)"; Alignment="right"; Expression={"{0:N2}" -f ($_.FreeSpace/1GB)}}, @{Label="Size(GB)"; Alignment="right"; Expression={"{0:N2}" -f ($_.size/1GB)}})
#$hosts
foreach($server in $hosts)
{
# WMI Commands
$os = Get-WmiObject Win32_OperatingSystem –computerName $server -ErrorAction SilentlyContinue
$machine = get-wmiobject win32_computersystem –computerName $server -ErrorAction SilentlyContinue
$bios = get-wmiobject Win32_bios -ComputerName $server -ErrorAction SilentlyContinue
# add a filter to only return the first CPU object - this is kinda bastard but generally CPUs will all be the same :)
$cpu = Get-WmiObject Win32_Processor –computerName $server -ErrorAction SilentlyContinue | select-object -first 1
#compute RAM in GB
$memory = get-wmiobject Win32_ComputerSystem –computerName $server
$memorygb = [Math]::Round($memory.TotalPhysicalMemory/1GB)
# IP Info
$addr = 0
$IPconfigset = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $server
foreach ($IPConfig in $IPConfigSet) {
if ($Ipconfig.IPaddress) {
foreach ($addr in $Ipconfig.Ipaddress) {
Out-String
}
}
}
#end IP
#Disk Info
$totalsize = 0
$totalfree = 0
#debug - what are we set to?
#$totalsize
#$totalfree
# Get fixed drive info
$disks = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3";
foreach($disk in $disks)
{
$deviceID = $disk.DeviceID;
[float]$size = $disk.Size;
[float]$freespace = $disk.FreeSpace;
#debug - what server?
#$server
#debug - what size did we find?
#write-host current disk ($size/1GB)
#debug - what is the current total?
#write-host total disk ($totalsize/1GB)
$totalsize += $disk.size
$totalfree += $disk.FreeSpace
}
#end disk
# Formatting the output
$output = New-Object PSObject
$output | Add-Member NoteProperty Name $server
$output | Add-Member NoteProperty NTDomain $machine.Domain
$output | Add-Member NoteProperty Manufacturer $machine.Manufacturer
$output | Add-Member NoteProperty Model $machine.Model
$output | Add-Member NoteProperty Serial $bios.SerialNumber
$output | Add-Member NoteProperty Type $machine.SystemType
#$output | Add-Member NoteProperty 64bit $cpu
$output | Add-Member NoteProperty TotalRAM $memorygb
$output | Add-Member NoteProperty NumberOfProcessors $machine.NumberOfProcessors
$output | Add-Member NoteProperty CPUName $cpu.Name
$output | Add-Member NoteProperty CPUSpeed $cpu.CurrentClockSpeed
$output | Add-Member NoteProperty IPInfo $addr
$output | Add-Member NoteProperty TotalDisk ($totalsize/1GB)
$output | Add-Member NoteProperty FreeDisk ($totalfree/1GB)
$output | Add-Member NoteProperty OSName $os.caption
$output | Add-Member NoteProperty ServicePack $os.CSDVersion
Write-Output $output | Export-Csv $P2VCandidates -noType -Append
}
$hosts=get-content "h:\scripts\hosts.txt"
$P2VCandidates="h:\scripts\ScriptOutput\P2VCandidatesOutput_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).csv"
$tableInfo=@("DeviceId", "VolumeName", @{Label="FreeSpace(GB)"; Alignment="right"; Expression={"{0:N2}" -f ($_.FreeSpace/1GB)}}, @{Label="Size(GB)"; Alignment="right"; Expression={"{0:N2}" -f ($_.size/1GB)}})
#$hosts
foreach($server in $hosts)
{
# WMI Commands
$os = Get-WmiObject Win32_OperatingSystem –computerName $server -ErrorAction SilentlyContinue
$machine = get-wmiobject win32_computersystem –computerName $server -ErrorAction SilentlyContinue
$bios = get-wmiobject Win32_bios -ComputerName $server -ErrorAction SilentlyContinue
# add a filter to only return the first CPU object - this is kinda bastard but generally CPUs will all be the same :)
$cpu = Get-WmiObject Win32_Processor –computerName $server -ErrorAction SilentlyContinue | select-object -first 1
#compute RAM in GB
$memory = get-wmiobject Win32_ComputerSystem –computerName $server
$memorygb = [Math]::Round($memory.TotalPhysicalMemory/1GB)
# IP Info
$addr = 0
$IPconfigset = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $server
foreach ($IPConfig in $IPConfigSet) {
if ($Ipconfig.IPaddress) {
foreach ($addr in $Ipconfig.Ipaddress) {
Out-String
}
}
}
#end IP
#Disk Info
$totalsize = 0
$totalfree = 0
#debug - what are we set to?
#$totalsize
#$totalfree
# Get fixed drive info
$disks = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3";
foreach($disk in $disks)
{
$deviceID = $disk.DeviceID;
[float]$size = $disk.Size;
[float]$freespace = $disk.FreeSpace;
#debug - what server?
#$server
#debug - what size did we find?
#write-host current disk ($size/1GB)
#debug - what is the current total?
#write-host total disk ($totalsize/1GB)
$totalsize += $disk.size
$totalfree += $disk.FreeSpace
}
#end disk
# Formatting the output
$output = New-Object PSObject
$output | Add-Member NoteProperty Name $server
$output | Add-Member NoteProperty NTDomain $machine.Domain
$output | Add-Member NoteProperty Manufacturer $machine.Manufacturer
$output | Add-Member NoteProperty Model $machine.Model
$output | Add-Member NoteProperty Serial $bios.SerialNumber
$output | Add-Member NoteProperty Type $machine.SystemType
#$output | Add-Member NoteProperty 64bit $cpu
$output | Add-Member NoteProperty TotalRAM $memorygb
$output | Add-Member NoteProperty NumberOfProcessors $machine.NumberOfProcessors
$output | Add-Member NoteProperty CPUName $cpu.Name
$output | Add-Member NoteProperty CPUSpeed $cpu.CurrentClockSpeed
$output | Add-Member NoteProperty IPInfo $addr
$output | Add-Member NoteProperty TotalDisk ($totalsize/1GB)
$output | Add-Member NoteProperty FreeDisk ($totalfree/1GB)
$output | Add-Member NoteProperty OSName $os.caption
$output | Add-Member NoteProperty ServicePack $os.CSDVersion
Write-Output $output | Export-Csv $P2VCandidates -noType -Append
}
DismountVMwareTools.ps1
######################################
# 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\Dismount-VMware-Tools_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).log"
##############################
# 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
##############################
# See if VM is powered on
##############################
if ($VMPower -notmatch "PoweredON") {
Write-Host $VMName `t "Powered OFF" -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`tNo Update`t`tPowered OFF")
}
##############################
# Update tools on VMs that meet prerequisites
##############################
else {
Dismount-Tools $VM
Write-Host $VMName `t $vmToolStatus `t "Dismounting Tools" -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tDismounting Tools`t`t" + $vmToolsStatus)
}
}
##############################
# Disconnect from vCenter
##############################
Disconnect-VIServer -server $global:DefaultVIServers -Force
##############################
# 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\Dismount-VMware-Tools_$((get-date).toString('MM-dd-yyyy_hh.mmtt')).log"
##############################
# 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
##############################
# See if VM is powered on
##############################
if ($VMPower -notmatch "PoweredON") {
Write-Host $VMName `t "Powered OFF" -ForegroundColor Red
Add-Content -Path $logFile -Value ($VMName + "`t`tNo Update`t`tPowered OFF")
}
##############################
# Update tools on VMs that meet prerequisites
##############################
else {
Dismount-Tools $VM
Write-Host $VMName `t $vmToolStatus `t "Dismounting Tools" -ForegroundColor Green
Add-Content -Path $logFile -Value ($VMName + "`t`tDismounting Tools`t`t" + $vmToolsStatus)
}
}
##############################
# Disconnect from vCenter
##############################
Disconnect-VIServer -server $global:DefaultVIServers -Force
##############################
OldLinuxVmwareTools.ps1
# 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
##############################
# 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
##############################
Subscribe to:
Posts (Atom)