Data Center Dan
  • Blog
  • About
  • Contact

Managing vSphere with Scripts

4/23/2014

0 Comments

 
There are a number of scripts out there—and I mean a lot—to help VMware administrators manage their environments. I plan on culling through some of these soon (or let me know your favorites) because so many are out-of-date and no longer function. I have to admit, this is certainly one (of the many) areas in which I need vast improvement. 

For the uninitiated, there are two basic kinds of scripting arenas available for VMware admins: the vSphere CLI, based on the traditional Windows batch file implementation, and vSphere PowerCLI, based on PowerShell. Both have lots of functions.  

vSphere CLI

The vSphere CLI, while poo-pooed by many today in light of the magnanimosity of PowerShell (tongue-in-cheek), is still very useful. I find my day-to-day operations are just as easy with it, albeit that I have a bunch of different scripts I already use on it. Certainly it is more limited than PowerCLI, however, it doesn't take as much training, either, and therefore you are more likely to use it!

The following example is my vCLI-SetRoundRobin script (downloads as a ZIP file). I have shrunk the font for format on the page. This script will go through and not only set defaults for all the various Storage Array Type Plugins (SATPs) to the Path Selection Policy (PSP) Round Robin, but will also reassign existing LUNs by rerunning the ESX storage claimrule load function (ESXi 4.1). Otherwise you can reboot your host afterward. 

@echo Off echo Beginning ESX Round Robin Setup...
echo Enter the ESX server IP address...
set /p server=
echo Enter the ESX server username...
set /p username=
echo Enter the ESX server password...
set /p password=
echo Enter the ESX server fiber channel adapter #1 (e.g., vmhba3)...
set /p vmhba1=
echo Enter the ESX server fiber channel adapter #2 (e.g., vmhba4)...
set /p vmhba2=

cd "\Program Files (x86)\VMware\VMware vSphere CLI\bin"

echo.
echo Beginning Round Robin defaults setup...
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_AA" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_ALUA" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_CX" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_ALUA_CX" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_SVC" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_INV" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_SYMM" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_EVA" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_EVA" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_DEFAULT_ALUA_CX" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_CX" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_ALUA_CX" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_EQL" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_INV" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_EVA" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_ALUA" --psp="VMW_PSP_RR"
esxcli --server %server% --username %username% --password %password% nmp satp setdefaultpsp --satp="VMW_SATP_SYMM" --psp="VMW_PSP_RR"
echo.
echo Round Robin defaults set.
echo.
echo Modifying existing path claim rules...
echo.
esxcli --server %server% --username %username% --password %password% corestorage claimrule load
esxcli --server %server% --username %username% --password %password% corestorage claimrule run
vicfg-rescan.pl --server %server% --username %username% --password %password% %vmhba1%
vicfg-rescan.pl --server %server% --username %username% --password %password% %vmhba2%
pause

vSphere PowerCLI

The vSphere PowerCLI is based on PowerShell and has a lot of functionality built-into it. I mean, there are entire classes and probably even career fields based on PowerShell and all it can do. So that makes it daunting for me. But at the same time, it is useful. 

Here is my vHostListIPs script that will go out and query the currently connected VI-Host (vCenter or single ESXi host) and list the IPs on the first vNIC of the VMX configuration file. Useful for updating Excel worksheets and such, and checking for misconfigurations when doing large deployments. 

A great resource is the vSphere PowerCLI Sample Scripts Library; it contains a lot of items that you can use to get started right away. 

Do you have Script Faves?

If you have a favorite vCLI or pCLI script, upload it to me and leave a comment—I will make sure to give you credit! 
0 Comments

    Author

    Husband.Father. Lifelong Learner & Teacher. #NetAppATeam. #vExpert.
    All posts are my own.

    Picture
    Picture
    Tweets by @dancbarber
    Check Out koodzo.com!

    Archives

    March 2017
    June 2016
    December 2015
    July 2015
    January 2015
    December 2014
    November 2014
    October 2014
    September 2014
    August 2014
    July 2014
    June 2014
    May 2014
    April 2014
    March 2014

    Categories

    All
    Best Practices
    Cisco Nexus
    Cisco UCS
    Cloud
    Compute
    Design
    Disaster Recovery
    ESXi
    Flash
    FlexPod
    Geeknicks
    HA/DRS
    HomeLab
    Horizon
    Hyper-Converged
    Management
    Memory
    NetApp
    Networking
    NFS
    Performance Optimization
    Power
    ProTips
    SAN
    Scripts
    Security
    Servers
    SQL
    Storage
    Training/Certification
    Troubleshooting
    VCenter
    VDI
    VMware
    VSOM/vCOPS
    VUM
    Windows

    RSS Feed