PoshCode Archive  Artifact Content

Artifact 1891fa796d993c0516ef0aa6eb197312c4c93e15880a645297ae78980a46d535:

  • File get-uuid_allHVs.ps1 — part of check-in [4e5eaf6ecb] at 2018-06-10 12:56:33 on branch trunk — #The PowerShell Talk (user: Cody Bunch size: 1511)

# encoding: ascii
# api: powershell
# title: get-uuid_allHVs.ps1
# description: #The PowerShell Talk
# version: 0.1
# type: script
# author: Cody Bunch
# license: CC0
# x-poshcode-id: 1152
# x-archived: 2013-10-16T19:57:26
# x-published: 2009-06-10T11:43:00
#
# #Building a HyperVisor Independent Script
# #
# #This script will take a VM (or host) object from the pipline, 
# #and from that determine if you’re connected to XenServer 
# #or VMware, and return the apropriate UUID.
#
#The PowerShell Talk
#Building a HyperVisor Independent Script
#
#This script will take a VM (or host) object from the pipline, 
#and from that determine if you're connected to XenServer 
#or VMware, and return the apropriate UUID.

Begin { 
	#VMware VM Host (ESX) UUID
	$VMHost_UUID = @{ 
        Name = "VMHost_UUID" 
        Expression = { $_.Summary.Hardware.Uuid } 
    }
	#XenServer Host UUID
	$XenHost_UUID = @{
		Name = "XenHost_UUID"
		Expression = { $_.Uuid }
	} 
}

Process { 
    #Get the type of object we have
	$InputTypeName = $_.GetType().Name 
    
	#Do something with that object
	#is it VMware?
	if ( $InputTypeName -eq "VMHostImpl" ) { 
        $output = $_ | Get-View | Select-Object $VMHost_UUID 
    #is it Xen?
	} elseif ($InputTypeName -eq "Host"){
		$output = $_ | Select-Object $XenHost_UUID 
	#Otherwise throw an error
	} else { 
        Write-Host "`nPlease pass this script either a VMHost or VM object on the pipeline.`n" 
    }
	$output
}