Skip to main content

Pure Storage PowerShell ESXi Connections

I have been using Pure Storage for a few months now and discovered that they have a PowerShell SDK to manage their storage system. My previous script for creating iSCSI connection from my host to the storage is great but it only creates the connection. The bit that was missing is to ensure the storage system authorises the ESXi to see the LUNS and usually you would need to pass the iSCSI IQN details to the storage admin. With the Pure Storage Powershell SDK I have now automated this section as well making my step towards Infrastructure as Code a step closer.

I will step through my script explaining;

Under the variables section we store all the relevant details

We store the Pure Storage Array management IP or FQDN name
$PureArrayIP = "Pure Storage Managment IP or FQDN"
In Pure Storage I group all the ESXi servers in “host groups” so I store the host group that I would like to have the ESXi host place in
$PureHostGroup = "Host Group Name"
Depending how you define your display name for host in Pure Storage you store the correct format information in this variable. For me we kept it simple where we just used the shortname of the ESXi server name which matches our vCenter server inventory
$ESXHost = "ESXi Host Display Name"
The iSCSI IQN name that belongs to the host that you are adding 
$ESXHostIQN = "IQN String"

First we check if Pure Storage SDK is installed, if it is not installed then we exit the script
If (!(Get-Module | Where {$_.Name -eq "PureStoragePowerShellSDK"}))
{Write-host "You need to install the PURE Storage PowerShell before carrying on"
Exit
}
Store the connection string in the variable $PureArray. The command will prompt for credentials to authenticate to the Pure Storage Array on the screen for you to input
$PureArray = New-PfaArray -EndPoint $PureArrayIP -Credentials (Get-Credential) -IgnoreCertificateError
We now get the $ESXHost detail from Pure Storage
$PureVMHost = Get-pfahosts -Array $PureArray| where {$_.name -eq $ESXHost}

The next section is where the actual work takes place. We first check if a value was returned for $PureVMHost
If (!$PureVMhost)
If no value was returned into that variable then it would mean that no such host information exists on the Pure Storage Array. So we issue a command to create a new host in Pure Storage and add the IQN details
New-PfaHost -Array $PureArray -Name $ESXHost -IqnList $ESXHostIQN  
We then add it to the host group within Pure Storage
Add-PfaHosts -Array $PureArray -Name $PureHostGroup -HostsToAdd $ESXHost
If the host exist on the storage array then we just issue a set/update command to change the iqn
Set-PfaHostIqns -Array $PureArray -Name $PureVMHost.Name -IqnList $ESXHostIQN


So with this script you can easily configure via lines of code in to Pure Storage for your ESXi hosts. From my previous script I had a section where I used a command to print the host iSCSI iqn name "$hba.iscsiname". This could be your input source for the IQN name into Pure Storage. The full code for the above script is at github. Pure Storage has good documentation around Powershell here to get you started. Happy scripting !!!

Comments

Popular posts from this blog

Rolling back a version of ESXi

There is an option in VMware where after you have performed an major upgrade of ESXi you can roll back to your previous version. The benefit of this is that you would not need to reinstall your ESXi and its configuration if you had issues with the new software. I had to do this on one occassion in my lab where I upgraded from 6.5 to 6.7 and my VMs would not run because the CPU was not supported in 6.7. Please remember if you are using ISO method to upgrade ESXi please ensure you select "Upgrade ESXi, preserve VMFS datastore". Selecting "Install ESXi, preserve VMFS datastore" does not mean preserving datastore means retaining ESXi as it will still do a clean install of ESXi. This method does not work for vSphere 7.0 as there are changes to the partitions on the boot device. Below are the steps to roll back to a previous version which is quite straight forward. As always perform an backup of your host configuration before you upgrade or rollback ( KB2042141 ). I have

Configuring ESXi 6 host to send logs to Syslog Server

In my previous post I talked about configuring VMware Syslog server for Windows which is installed and enabled by default on installation of vCenter 6 for Windows. I will now describe the basic configuration that is required on an ESXi 6 host to be able to send logs out to a syslog server using my vCenter as the example. 1) Navigate to your ESXi host within vCenter. Go to "Manage" tab and select "Settings" followed by "Advanced System Settings". Look for the settings "Syslog.global.loghost" and highlight this settings. Click the pencil icon to edit the configuration for this setting. 2) You can now add the host name or ip address of your syslog server/s. You can enter just hostname or IP address, use udp://hostname:514 or ssl://hostname:1514 to be more specific on the port and protocol to be used. If you have multiple hosts then you use the comma (,) to separate each server i.e. udp://192.168.0.1:514,udp://192.168.0.2:514 3)We n

Custom ESXi Image - ISO using PowerCLI

There comes a time when you have purchased a new hardware to run your ESXi software and discover that the installable base media provided by VMware does not include the drivers or the drivers are out of date. In the world of Windows (Plug and Play) it would discover the hardware and prompt you to provide the drivers so that Windows would install/update the drivers for the hardware. For ESXi if the drivers are not present during load time then the hardware will possibly not work. VMware uses VIB (vSphere Installation Bundle) as a way for vendors to distribute their drivers. To install these VIBs you can either use Update Manager or command line (esxcli). Now this is all good but it does mean you have to first install the base ESXi then use one of the steps above to install/update the drivers.   Some people might feel that it is OK to update the drivers using the above methods but what if it was the network card that was the new hardware and you needed new drivers. Without the net