Angels Technology

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Tuesday, August 6, 2013

GET UUID of your hosts.

Posted on 10:07 AM by Unknown


While you can get the uuid of your hosts 1 by 1
https://<HOST>/mob/?moid=ha%2dhost&doPath=hardware%2esystemInfo

but when you have a lot of hosts that is a little time consuming to do that.
This script from http://thephuck.com/scripts/script-to-pull-host-uuid-for-vmware-powercli/
has the ability to get all the uuids from the hosts you have.
Thanks Luke Huckaba!

Worked great


Usage is like this:
Get-VMHostUUID.ps1 -vmhosts ("host1","host2","host3")or
Get-VMHostUUID.ps1 -vc vcenterserver -container cluster1/folder/dc/etc

param([string]$vc = "vc", [string]$container = "container", [string[]]$vmhosts = $null)

#add the snapin, just in case
Add-PSSnapinVMware.VimAutomation.Core

#Show Usage
function usage()
        {
        Write-host -foregroundcolorgreen `n`t"This script is used to pull UUIDs for all hosts provided."
        Write-host -foregroundcolorgreen `n`t"You can either specify -vmhosts as an array:"
        write-host -foregroundcoloryellow `n`t`t"Get-VMHostUUID.ps1 -vmhosts (`"host1`",`"host2`",`"host3`")"
        write-host -foregroundcolorgreen `n`t"or specify -vc and -container, where container is a host name, cluster, folder, datacenter, etc:"
        write-host -foregroundcoloryellow `n`t`t"Get-VMHostUUID.ps1 -vc vcenterserver -container cluster1" `n
    write-host -foregroundcolorgreen `t"if -container is not used, it pulls ALL hosts from the given vCenter" `n
           write-host -foregroundcolorgreen `t"You can use either -vmhosts by itself, or -vc, not a combination of them, and -container is optional."`n
        }

function Get_UUID()
{
    foreach($vmhost in $vmhosts)
        {
           if ($esx -eq 1)
           #do this only if connecting directly to ESX hosts
                {
                connect-viserver $vmhost -credential$vmhost_creds >$NULL 2>&1
                }
        $vmhostUUID= (Get-VMHost $vmhost| Get-View).hardware.systeminfo.uuid
    Write-Host`n
        Write-Host -foregroundcolorgreen "Server: " $vmhost
        write-host -foregroundcolorgreen "UUID: " $vmhostUUID
            if ($esx -eq 1)
            #disconnect from the current ESX host before going to the next one
        {
        disconnect-viserver -confirm:$false
        }
        }
            if($vcenter -eq 1)
        #disconnect from vcenter
        {
        disconnect-viserver -confirm:$false
        }     
}

#check to make sure we have all the args we need
if (($vmhosts -eq $null) -and ($vc -eq "vc"))
    #if vmhosts and vc is not supplied
        {
        usage
    break
        }

elseif (($vmhosts -ne $null) -and ($vc -ne "vc"))
    #if both vmhosts and vc was supplied
        {
        usage
    break
        }

elseif (($vmhosts -ne $null) -and ($container -ne "container"))
    #if both vmhosts and container was supplied
        {
        usage
    break
        }

elseif (($vmhosts -ne $null) -and (($vc -eq "vc") -or ($container -eq "container")))
    #if only vmhosts is used, set our esx variable to 1 and get credentials
        {
    $esx= 1
    $vmhost_creds= $host.ui.PromptForCredential("ESX/ESXi Credentials Required", "Please enter credentials to log into the ESX/ESXi host.", "", "")
    Get_UUID
    }

elseif (($vmhosts -eq $null) -and (($vc -ne "vc") -and ($container -eq "container")))
    #if vc and container are used, set our vcenter variable to 1, get credentials, and populate vmhosts
        {
    $vcenter= 1
    $vc_creds= $host.ui.PromptForCredential("vCenter Credentials Required", "Please enter credentials to log into vCenter.", "", "")
    connect-viserver $vc -credential $vc_creds> $NULL 2>&1
    $vmhosts= get-vmhost| sortname
    Get_UUID
        }

elseif (($vmhosts -eq $null) -and (($vc -ne "vc") -and ($container -ne "container")))
    #if vc and container are used, set our vcenter variable to 1, get credentials, and populate vmhosts
        {
    $vcenter= 1
    $vc_creds= $host.ui.PromptForCredential("vCenter Credentials Required", "Please enter credentials to log into vCenter.", "", "")
    connect-viserver $vc -credential $vc_creds> $NULL 2>&1
    $vmhosts= get-vmhost-location $container| sortname
    Get_UUID
        }

#garbage collection
$vmhost_creds =$null
$vc_creds = $null
$vmhosts = $null
$vc = $null
$container = $null
$esx = $null
$vcenter =$null


Output is something like this:
Server: server1
UUID: 12345678-90ab-cdef-1234-567890abcdef
Server: server2
UUID: 12345678-90ab-cdef-1234-567890abcdef
Server: server3
UUID: 12345678-90ab-cdef-1234-567890abcdef

Pasted from <http://thephuck.com/scripts/script-to-pull-host-uuid-for-vmware-powercli/>

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Convert your physical RDM (rdmp) to a virtual RDM (rdmv)
    So you have a raw disk mapping on your virtual machine in esxi   and you wanted to convert it from a rdmp to a rdmv. Using the VMware cli...
  • How to read PSOD errors on your esxi host
    Here are some links that are useful to help you interpret why psod errors are happening. Machine Check Exception errors: mce http://kb.vmwar...
  • How to run a powershell script for vmware : walkthrough
    Here is a walk through on how to make and run a powershell /powercli script The methods also apply to powershell but this is target towa...
  • Esxi : Recovering from a bad update : Last known good configuration for vmware
    Recovering from a bad update. Press Shift+R at the boot prompt. Esxi should fall back to the last known good state. You have t o be real fas...
  • Browsing Vmware logs in the DCUI (view esxi logs via console)
    Why would you view your logs in the console? Well sometimes it's the only place that is accessible if there is an error. Go to your DC...
  • Vmware DRS anti affinity rules wont let you enter maintenance mode for a esxi host
    You have a DRS rule that specifies that 2 vms need to be kept apart: In this case: 250-FT and 250sql3 For larger clusters with multiple...
  • Check esxi host's disk latency / storage performance using DAVG in esxtop
    Do youyour virutal machine's seem slow? Is it your vm or is it your disk storage or san? This is how we can check. What is davg This...
  • How to add a Raw disk to your esx host (RDM)
    RDM, raw device mapping allows for a virtual guest to access a provisioned disk or lun directly and perform operations on it. Use physical...
  • Copy-vmguestfile :: Copying data from powercli to a guest virtual machine, even an isolated machine!
    Did you know you can copy files to a vm using virtual tools? This would be great for disconnected or isolated vms that need files. Che...
  • Powercli script to check vmotion compatibility to another host
    This thread here shows you how to test vmotion compatibility to a specific host. It’s a good starting point. The return value are usin...

Categories

  • 5.1
  • backup
  • cloud
  • cluster
  • command line
  • console
  • converter
  • cpu
  • datacenter
  • datastore
  • datastore. rdm
  • DCUI
  • dell
  • disaster recovery
  • display
  • DR
  • e1000
  • e1000e
  • ec2
  • esx
  • esxi
  • esxtop
  • extent
  • Good for enterprise
  • HA
  • hcl
  • host
  • HP
  • ibm
  • iometer
  • iscsi
  • iso
  • linked mode
  • logs
  • MAC
  • memory
  • NFS
  • NIC
  • NTP
  • ova
  • ovf
  • p2v
  • pcie
  • performance
  • phone
  • powercli
  • powershell
  • PSOD
  • raid
  • RDM
  • resource pool
  • rvtools
  • scsi
  • sddc
  • snapshots
  • SQL
  • SRM
  • ssh
  • storage
  • svmotion
  • syslog collector
  • v2v
  • vapp
  • vcenter
  • vcloud
  • vcp
  • veeam
  • VI console
  • vm
  • vmdk
  • VMFS
  • vmkfstools
  • vmotion
  • VMUG
  • vmware
  • vmware tools
  • vmware.esxi
  • vmxnet3
  • vsphere
  • vum
  • web client
  • windows

Blog Archive

  • ▼  2013 (28)
    • ►  October (2)
    • ►  September (1)
    • ▼  August (1)
      • GET UUID of your hosts.
    • ►  July (1)
    • ►  June (14)
    • ►  May (1)
    • ►  April (1)
    • ►  March (5)
    • ►  February (1)
    • ►  January (1)
  • ►  2012 (138)
    • ►  December (2)
    • ►  November (13)
    • ►  October (26)
    • ►  September (19)
    • ►  August (35)
    • ►  July (34)
    • ►  June (9)
Powered by Blogger.

About Me

Unknown
View my complete profile