Search This Blog

Friday, April 6, 2012

An Easy way to get VMhost UUID

I saw a blog for getting a VMhost UUID.  UUID is sometimes needed. In my case I needed it to license EMC Powerpath VE.

There's a an easy way than going through all that.

Get-VMhost | Get-View | % { $_.hardware.systeminfo.uuid }

That's it. If you want to get fancy and have a need for speed (if you have many VMhosts):

Get-View -ViewType HostSystem -Propert Name, hardware.systeminfo -Filter @{"Name"="VMHostNameHere" }  | % { $_.hardware.systeminfo.uuid }

If you want to get even fancier and return the host name with the UUID, here's a little trick using SELECT:

Get-View -ViewType HostSystem -Propert Name, hardware.systeminfo -Filter @{"Name"="VMHostNameHere" }  | Select Name, @{N="UUID" ; E={$_.hardware.systeminfo.uuid } }

Notice the "N=" and "E=" clauses? N means NAME and E means expression.

No offense to http://thephuck.com/scripts/script-to-pull-host-uuid-for-vmware-powercli/comment-page-1/ . Visit it, It's a nice blog.

Wednesday, January 18, 2012

a VERY LONG onliner to get Cisco CDP from a VMware dvSwitch (or vSwitch)

Here's a VERY LONG onliner to get Cisco CDP (Cisco Discovery Protocol) info of vmnics (Ethernet adapters) connected to physical or virtual switches. In this case, the vmnics are physical. So this script GETS physical switch output. See example below:

This Oneliner is broken into mutiple lines for ease of use. But it can be condensed to ONE LINE. Yehaw!
Get-view -ViewType HostSystem -Filter @{"Name"="$VMhost"} -Property ConfigManager.NetworkSystem, Name | sort name | % { $n=$_.name ; $objConfigManager_NetworkSystem = get-view $_.ConfigManager.NetworkSystem ; $objConfigManager_NetworkSystem | % { $_.NetworkInfo } | % { $_.Pnic } | SELECT @{N="Name"; E={$n} } , device, pci, mac, @{N="PortID" ; E= { $objConfigManager_NetworkSystem.QueryNetworkHint($_.Device) | % { $_.ConnectedSwitchPort.PortID } } }, @{N="DevID" ; E= { $objConfigManager_NetworkSystem.QueryNetworkHint($_.Device) | % { $_.ConnectedSwitchPort.DevID } } } | ? { $_.Device -match "vmnic" }
}

Output Example:
NameDevicePCIMACPortIDDeviceID
esxhstesx01.us.ano.netvmnic001:00.000:34:84:5d:75:a4GigabitEthernet2/0/9C3750x.phx.az.anon.com
esxhstesx01.us.ano.netvmnic101:00.100:23:44:5d:75:a6GigabitEthernet1/0/11C3750x.phx.az.anon.com
esxhstesx01.us.ano.netvmnic204:00.000:43:33:90:77:78GigabitEthernet2/0/11C3750x.phx.az.anon.com
esxhstesx01.us.ano.netvmnic304:00.100:77:33:90:77:79GigabitEthernet1/0/9C3750x.phx.az.anon.com

Tuesday, November 1, 2011

One liner to get VMNIC and PCI adapter positions

  Here's a oneliner I recently used to get vmnic and PCI adapter positions. The PCI slot numbers were needed for automated deployment of ESXi hosts and the h

Get-vmhost $VMhost | % {$x=$_; $x| get-view | % { get-view $_.ConfigManager.NetworkSystem  }  |  % { $_.NetworkInfo  } | % { $_.Pnic  } | Select @{N="VMhost"; E={$x} } , device, pci, mac  } 

Stay tuned for the really fast version. 

Friday, September 9, 2011

Automated Script to re-register VM

There's a bug in vSphere 4.* that requires your to re-register/reregister  (remove then re-add) before you can edit the VM. VMware has a workaround (http://kb.vmware.com/kb/1025367), so here's the PowerCLI code that makes it easier:

param ($VM, [switch]$WhatIf=$False, [switch]$RunAsync = $False)
#script to re-register a vm

process{

     if ($_){
          $VM = $_
     }

     if (( $VM | GM)[0].TypeName -match "VirtualMachineImpl|TemplateImpl"){

          foreach ($v in $vm){

               if (( $v | GM)[0].TypeName -match "TemplateImpl"){
                    $v = $v | Set-Template -ToVM -confirm:0
                    $RunAsync = $False
               }

               $VMFilePath = $v | Get-View | % { $_.Config.Files.VmPathName } 
               #$vuid =  $v | % { $_.Uid.Split("/")[1] }

               if ( ( $VMFilePath ) -and ($v.VMHost.ConnectionState -eq "Connected") ){

               $zn = Remove-VM -vm $v -DeletePermanently:0 -whatif:$whatif -confirm:0  
               New-VM -Name $v.name -WhatIF:$whatif -VMHost $v.vmhost -VMFilePath $VMFilePath -Location $v.Folder   -RunAsync:$RunAsync

               }elseIf ($v.VMHost.ConnectionState -ne "Connected" ){
                    write-host -foreground red -background white $v.name on $v.VMhost is $v.VMhost.ConnectionState

               }
          }

     }else{ 
          write-host -fore Yellow "-VM Not VIrtualMachineImpl" 
     }
}

Wednesday, August 3, 2011

Nine (9) new vSphere 5 new white papers

VMware 9 new vSphere 5 new white papers. Other sites post links to sites with links. Since that bugs me, below are the direct URL to the white paper PDF files.


1.       VMware vSphere Storage Appliance Technical Whitepaper

http://www.vmware.com/files/pdf/techpaper/VMware-vSphere-Storage-Appliance-Technical-Whitepaper.pdf

2.       What's New in VMware Data Recovery 2.0 Technical Whitepaper

http://www.vmware.com/files/pdf/techpaper/Whats-New-VMware-Data-Recovery-20-Technical-Whitepaper.pdf

3.       What's New in VMware vCenter Site Recovery Manager 5.0 Technical Whitepaper

http://www.vmware.com/files/pdf/techpaper/Whats-New-VMware-vCenter-Site-Recovery-Manager-50-Technical-Whitepaper.pdf

4.       What's New in VMware vCloud Director 1.5 Technical Whitepaper

http://www.vmware.com/files/pdf/techpaper/Whats-New-VMware-vCloud-Director-15-Technical-Whitepaper.pdf

5.       What's New in VMware vSphere 5.0 Availability

http://www.vmware.com/files/pdf/techpaper/Whats-New-VMware-vSphere-50-Availability-Technical-Whitepaper.pdf

6.       What's New in VMware vSphere 5.0 Performance

http://www.vmware.com/files/pdf/techpaper/Whats-New-VMware-vSphere-50-Performance-Technical-Whitepaper.pdf

7.       What's New in VMware vSphere 5.0 Storage

http://www.vmware.com/files/pdf/techpaper/Whats-New-VMware-vSphere-50-Storage-Technical-Whitepaper.pdf

8.       What's New in VMware vSphere 5.0 Networking

http://www.vmware.com/files/pdf/techpaper/Whats-New-VMware-vSphere-50-Networking-Technical-Whitepaper.pdf

9.       What's New in VMware vSphere 5.0 Platform

http://www.vmware.com/files/pdf/techpaper/Whats-New-VMware-vSphere-50-Platform-Technical-Whitepaper.pdf

 

 

Wednesday, July 13, 2011

Get-FT.ps1 - A script to get VM's running FT (Fault Tolerance)

This is a short and simple PowerCLI script for vSphere, but because it uses Get-VIEW, it's super fast.


$ft = get-view -ViewType VirtualMachine -filter @{"Config.FtInfo.Role"="1|2|3"}

$ft | select Name, @{N="Role" ; E={$_.Config.FtInfo.Role } }, @{N="RecordReplayState" ; E={$_.Runtime.RecordReplayState } }, @{N="FaultToleranceState" ; E={$_.Runtime.FaultToleranceState} }


Save this to an ANSI text file and run it against your connected vCenter.

Enjoy!

Tuesday, April 26, 2011

ESXi SNMP Configuration

I see a lot of erroneous blogs for configuring SNMP in ESXi 4.1u1. To set the record straight, here's my erroneous :) blog post for configuring SNMP ESX and ESXi 4.1 and 4.1u1.

VMware Remote CLI is imperative (but not required if you want to use a different method). RCLI should not be confused with PowerCLI. They are different tools and do different things. RCLI contains remote management batch files which use PERL to connect to the VMware API.

Now, Install VMawre Remote CLI. The vCenter server is convenient but your local desktop works too.  Once installed, you'll get a command prompt shortcut. If you don't see it, it will be under the start/programs/Vmware/Vmware vSphere CLI. Run it.

Under the directory which RCLI launches, there's a BIN directory. CD BIN to get to that directory. Now the RCLI scripts can execute.

The vicfg-snmp.pl -s displays existing settings. BTW, vicfg-snmp.pl = esxcfg-snmp.pl. They are the same.

vicfg-snmp.pl --username root --password yourpw --server esxihost-s

The vicfg-snmp.pl -D disables SNMP.
vicfg-snmp.pl --username root --password yourpw --server esxihost-D

The vicfg-snmp.pl -t sets the community string and SNMP target server. 
vicfg-snmp.pl --username root --password yourpw --server esxihost -t %srvsnmp%/MY-RO -communities MY-RO

The vicfg-snmp.pl -D enables SNMP.
vicfg-snmp.pl --username root --password yourpw --server esxihost