- Community Home
- >
- Storage
- >
- HPE Nimble Storage
- >
- Array Setup and Networking
- >
- quick powershell script for adding esxi hosts
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
09-30-2016 11:51 AM
09-30-2016 11:51 AM
quick powershell script for adding esxi hosts
Well I wont say this is the most polished script, and you will need to modify a few of the specific variables to your environment, but it's quick, dirty, and works.
in my environment, i only have a single initiator group for all hosts. Wrote this script to add additional esxi hosts via iscsi to the nimble.
need vmware powerCLI installed, and the nimble power shell toolkit as well.
script;
gets vmware hosts.
creates a standard vswitch with specified vmnics (set vmnics specific to your environment)
creates two vmkernel adapters. bound to each vmnic (active / disabled)
enables software iscsi initiator
bounds vmkernal adapters to the iscsi initiator
registeres the iqn on the nimble initiator group
adds the target ip's to the iscsi initiator
rescans
# ############################################################################################
#
#
# Network config for Standard Edition Hosts - Control Cluster.
#
# Also can be modified to add iscsi to existing hosts.
#
#
# ############################################################################################
# ######### BEGIN HERE #####################################################################
# ############################################################################################
import-module NimblePowerShellToolKit
Connect-VIServer yourVcenterServer
# VARIABLES
$vmhost = get-vmhost | where-object { $_.Name -like "filter*"}
$targets = "1.2.3.4","1.2.4.4" #iScsi targets to add to hosts (if not already there)
$ip1 = "10.1.1." # base IP address for iScsi vlan 1
$ip2 = "10.1.2." # base IP address for iScsi vlan 2
#Array of last octect IP addresses for corresponding host names
$ipHost = @{"host1" = "101";
"host2" = "102";
"host3" = "103"
}
$nimbleCreds = Get-Credential -Message "Enter Credentials for Nimble Array" -UserName "admin"
Connect-NSGroup -Group 1.2.3.4 -credential $nimbleCreds
# grab initiatorGroup from Nimble.
$nimbIGroup = Get-NSInitiatorGroup -name initiatorGroup
# ############################################################################################
foreach ($esx in $vmhost) {
$oct = $IPHost.get_Item($esx.Name.Split(".")[0])
#vmStorage Switch - this can be a standard switch for all hosts.
#Create/Get Virtual Switch
if (-not($vSwitch = Get-VirtualSwitch -VMHost $esx -Name vmStorage 2>null))
{ $vSwitch = New-VirtualSwitch -VMHost $esx -Name "vmStorage" -Nic vmnic4,vmnic5 }
#$vSwitch = Get-VirtualSwitch -VMHost $esx -Name vmStorage
#1 Portgroup and nic policy
if (-not ( $pg = Get-VirtualPortGroup -VirtualSwitch $vSwitch -Name "iSCSI 1" 2>null ))
{ $pg = New-VirtualPortGroup -VirtualSwitch $vSwitch -Name "iSCSI 1" -VLanID 1 }
$pg | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic4 -MakeNicUnused vmnic5
New-VMHostNetworkAdapter -VMHost $esx -PortGroup $pg -virtualSwitch $vSwitch -IP "$ip1$oct" -SubnetMask 255.255.255.0
#store the vmkx name for this adapter
$vmk0 = $(Get-VMHostNetworkAdapter -VMHost $esx -PortGroup $pg -virtualSwitch $vSwitch ).Name
#2 Portgroup and nic policy
if (-not ( $pg = Get-VirtualPortGroup -VirtualSwitch $vSwitch -Name "iSCSI 2" 2>null ))
{ $pg = New-VirtualPortGroup -VirtualSwitch $vSwitch -Name "iSCSI 2" -VLanID 2 }
$pg | Get-NicTeamingPolicy | Set-NicTeamingPolicy -MakeNicActive vmnic5 -MakeNicUnused vmnic4
New-VMHostNetworkAdapter -VMHost $esx -PortGroup $pg -virtualSwitch $vSwitch -IP "$ip2$oct" -SubnetMask 255.255.255.0
#store the vmkx name for this adapter
$vmk1 = $(Get-VMHostNetworkAdapter -VMHost $esx -PortGroup $pg -virtualSwitch $vSwitch ).Name
#iSCSI setup
#Create Software iSCSI Adapter
get-vmhoststorage $esx | set-vmhoststorage -softwareiscsienabled $True
#Get Software iSCSI adapter HBA number and put it into an array
$HBA = Get-VMHostHba -VMHost $esx -Type iScsi | Where-Object {$_.Model -eq "iSCSI Software Adapter"}
#add the vmkernel adapters to the software iscsi adapter.
$Esxcli = Get-EsxCli -VMHost $esx
$Esxcli.iscsi.networkportal.add($HBA, $Null, $vmk0)
$Esxcli.iscsi.networkportal.add($HBA, $Null, $vmk1)
#add the iniator to the Nimble initiator
if (-not(Get-NSInitiator | where-object { $_.iqn -eq $HBA.IScsiName } ))
#create the initiator if it doesn't exist
{ New-NSInitiator -initiator_group_id $nimbIGroup.id -access_protocol iscsi -label $esx.name -iqn $HBA.IScsiName }
# add the targets to the software iscsi initiator
foreach ($target in $targets){
if (Get-IScsiHbaTarget -IScsiHba $HBA -Type Send | Where {$_.Address -cmatch $target}) {
Write-Host "The target $target does exist on $esx" -ForegroundColor Green
} else {
Write-Host "The target $target doesn't exist on $esx" -ForegroundColor Red
Write-Host "Creating $target on $esx ..." -ForegroundColor Yellow
New-IScsiHbaTarget -IScsiHba $hba -Address $target
}
}
$esx | Get-VMHostStorage -RescanAllHba
}
# ############################################################################################
# ############## END CODEBLOCK #############################################################
# ############################################################################################
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
10-03-2016 06:51 AM
10-03-2016 06:51 AM
Re: quick powershell script for adding esxi hosts
Hi Jared, nice work! Thanks for sharing it with the community. I love seeing the Nimble Powershell Toolkit put to good use.
One comment I did want to make was about the binding of your VMkernel ports to the iSCSI software adapter. It looks like you are setting up iSCSI connections on two separate subnets. In this configuration, VMware states that you should not be binding the VMkernel ports to the software iSCSI adapter. Check out VMware KB 2038869 for more detail.
Cheers!
Julian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
10-03-2016 09:19 AM
10-03-2016 09:19 AM
Re: quick powershell script for adding esxi hosts
well learn something new everyday.
I wasn't aware of the binding discussion, i've just always bound ports, didn't even realize the software initiator would work without having bound ports.. (although i do have more dead paths with unbound, but i dont think that's actually an issue)
Thanks.
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP