Virtualization, Cloud, Infrastructure and all that stuff in-between

My ramblings on the stuff that holds it all together

POSH1Liner:Configure all hosts in a cluster

ok, a little more than a 1-liner; but a shell loop that you can use to do *something* to all hosts in a given cluster (in this case the cluster is called L2-C2; 2nd level of virtualization, e.g. not physical which is L1, 2nd cluster if you’re interested in my naming convention)

in this case it’s adding an iSCSI software adapter and pointing it at some targets – pause is optional (assumes you’re already connected to a vCenter via connect-vihost)

# Generic shell
$cluster = get-cluster L2-C2 | get-vmhost
foreach ($hypervisor in $cluster) {

write-host Doing config for $hypervisor
#Do stuff here for each host in the cluster $hypervisor is the hostname variable
Get-VMHostStorage -VMHost $hypervisor | Set-VMHostStorage -SoftwareIScsiEnabled $True
get-vmhost -name $hypervisor | Get-VMHostHba -Type iScsi | Where {$_.Model -eq “iSCSI Software Adapter”}
Get-VMHost -name $hypervisor | Get-VMHostHba -Type iScsi | New-IScsiHbaTarget -Address “172.16.20.20”
Get-VMHost -name $hypervisor | Get-VMHostHba -Type iScsi | New-IScsiHbaTarget -Address “172.16.20.21”
get-vmhost -name $hypervisor | get-VMhostStorage -refresh -RescanAllHba -RescanVmfs
write-host “————————————————————————————-”
pause #wait for keypress

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: