Wednesday, May 15, 2013

Export CDP info using Powercli

I was asked the other day to export cdp information from esx hosts at a client site to file. I used the vmware kb here that has source code for powercli. I just took this code and ammended it to export to a file instead of the console. Here is my ammended code.

$logfile = "c:\Temp\cdpinfo.txt"
Connect-VIServer vcenterhostname -User domain\username -Password password
Get-Datacenter | Get-VMHost | Where-Object {$_.State -eq "Connected"} |
%{Get-View $_.ID} |
%{$esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} |
%{ foreach($physnic in $_.NetworkInfo.Pnic){
    $pnicInfo = $_.QueryNetworkHint($physnic.Device)
    foreach($hint in $pnicInfo){
       $esxname | Out-File $logfile -Append
    $physnic.Device | Out-File $logfile -Append
      if( $hint.ConnectedSwitchPort ) {
        $hint.ConnectedSwitchPort | Out-File $logfile -Append
      else {
        "No CDP information available." | Out-File $logfile -Append

Saturday, May 4, 2013

Provisioning Dell EqualLogic iscsi Storage to esxi without Vcenter

There are certain circumstances where having a script that can execute in these situations is helpful. I tend to use this script to speed up the build process while waiting on VCenter and Hitkit install/configurations to proceed.
 The script can be downloaded here. I'll do a walkthrough of the script to explain how it works.

As you can see in lines 8 and 9 from the import-module commands the Dell Hit Kit for windows and VMware powercli are required to be installed to make this work.
Line 11 is an input variable for the EQ Group IP. Line 12 input file is the service console IPs/hostnames of all the esx hosts you are connecting to. Line 13 is the name of the volumes you would like to create with the size of each volume. The syntax of each input file is referenced below.

esxhosts.txt - input file contents below

volumes.csv - input file contents below

After the input variables have been defined the next section of the script grabs the IQN information from all the esxi hosts. There is an assumption made at this point that you have already enable all the iscsi initiators on your esxi host and bound them to a vmkernel interface. NOTE: If there isn't atleast one iqn available for each host then the script stops.

Once we have established a list of all the active IQNs the script connects to the EQ via Dell hitkit tools for windows and provisions the volumes you indicated in the volumes.csv file with ACLs for the IQNs grabbed earlier.
 The next order of business is to grab the naa information from the storage array for each of the volumes we created. You can see below in lines 39 through 44 I started parsing this data out from the PSVID property.
  The other parts appear to be pretty self explanatory. I disconnected from the array and then establish a connection to the first host in the host file to format the volumes then perform storage rescans on all the hosts.