VMware Cloud Community
tonygent
Enthusiast
Enthusiast

Examples from a Newb - 2

OK - A couple more examples that may assist othher Newb's. Please feel free to suggest better code structure or other tips.

Thanks

TG

  1. Purpose : Get LVM Settings for all Hosts in a Cluster

#Main

$strVC = ""

$strCLUSTER = ""

Connect-VIServer $strVC

$oCluster = Get-Cluster -name $strCLUSTER

write-host $oCluster

$oHosts = $oCluster | Get-VMHost -state "Connected"

Foreach ($ohost in $oHosts)

{

Echo $oHost.Name

$esx = Get-View $oHost.ID

$optmgrMoRef = $esx.configManager.advancedOption

$optmgr = Get-View $optmgrMoRef

$optarray = $optmgr.QueryOptions("LVM.DisallowSnapshotLun")

$iDSL = $optarray[0].Value

Echo "LVM.DisallowSnapshotLun = $iDSL"

$optarray = $optmgr.QueryOptions("LVM.Enableresignature")

$iES = $optarray[0].Value

Echo "LVM.EnableReSignature = $iES"

}

Disconnect-VIServer -Confirm:$False

  1. Purpose : Shutdown a VM Cleanly

#Main

$strVC = ""

$strVM = ""

Connect-VIServer $strVC

#Assign VM object to a variable

$objVM = Get-VM -name $strVM

write-host "Shutting down VM : " $objVM.Name

#Submit the object to the Shutdown-vmguest cmdlet

shutdown-vmguest $objVM

Disconnect-VIServer -Confirm:$False

Reply
0 Kudos
0 Replies