First Published On: 03-16-2017 Last Updated On: 07-31-2017 1
Table of Contents 1. PowerCLI 1.1.PowerCLI Overview 1.2.PowerCLI Blog 1.3.PowerCLI - VMTN Communities 1.4.PowerCLI Community Repository 1.5.PowerCLI Installation Walkthrough 2. vsphere CLI (vcli) 2.1.vSphere CLI - Overview 2.2.Datacenter CLI (DCLI) - Overview 2.3.DCLI - Interactive Mode 2.4.DCLI - Scripting Mode 2.5.DCLI - Getting Started Demonstration 2
1. PowerCLI VMware PowerCLI is a command-line and scripting tool built on Windows PowerShell which is used when managing and automating vsphere, vcloud, Horizon View, and more! 3
1.1 PowerCLI Overview VMware PowerCLI Overview VMware PowerCLI is a fantastic, free, command line and scripting tool that can be used to manage and automate many of VMware s products. If you ve worked with a VMware product, there s a good chance you ve already heard of it. PowerCLI is an extension of Windows PowerShell. PowerShell is an object-oriented programming language from Microsoft which is used for the automation of tasks as well as configuration management. Interacting with PowerShell is done through the use of cmdlets, which are formatted in a verb-noun pairing that is quite intuitive to the user. Additional cmdlets can be added to a PowerShell session by either snap-ins or modules. This is important to know because PowerShell can access and make use of the PowerCLI modules. While PowerShell has access to those modules, the user can then access over 500 different cmdlets It is an important command line interface (CLI) for a number of reasons that should be taken into consideration when selecting which VMware CLI should be used for the task at hand. First and foremost, PowerCLI has the widest coverage of VMware s CLIs. PowerCLI works with vsphere and many of its features including Auto Deploy, vsan, and Update Manager. PowerCLI also works with products outside of vsphere, such as Horizon View, Site Recovery Manager, vrealize Operations, and vcloud Air. PowerCLI also has an amazing user community! The VMware PowerCLI VMTN Communities boasts over 11,000 difference discussions where anyone from users to PowerCLI engineers can respond to questions, comments, or issues. Then, there is the PowerCLI Twitter handle which is closing in on 8,000 followers. There has also been a recent addition in the form of the VMware Code Slack team which has a PowerCLI channel that remains one of the most active channels with over 250 people joined. Lastly, PowerCLI has gone multi-platform. One of the largest complaints about PowerCLI was that it was limited to only being run on Windows based system. Well, PowerCLI has fully embraced Microsoft s open sourcing of.net and PowerShell and released a PowerCLI Core Fling! This fling allows Linux and Mac OS users to also run PowerCLI. 1.2 PowerCLI Blog PowerCLI is one of the few tools that features its own VMware blog! The PowerCLI blog contains over 300 different posts, which all focus on some form of technical content. Some of the posts are on new product announcements, others are on cmdlet deep dives and functional examples, and the list goes on. The blog can be found at the following URL: < http://blogs.vmware.com/powercli/ > 1.3 PowerCLI - VMTN Communities 4
The VMware VMTN Community for PowerCLI boasts over 11,000 difference discussions where anyone from users to PowerCLI engineers can respond to questions, comments, or issues. The community also features one of the highest rates of responses as well. It is extremely rare to see a discussion without at least one response. It is a great resource to not only receive answers to questions, but to browse as a learning tool. 1.4 PowerCLI Community Repository The VMware PowerCLI Community Repository < https://github.com/vmware/powercli-example- Scripts > is a central location where anyone can view and contribute their PowerCLI based resources. The repository is openly available from VMware s GitHub account. There are over 30 scripts, 15 modules, several PowerActions items, and other resources available today, with many more being added on a daily basis. The repository features a Principles of Operations < https://github.com/vmware/powercli-example- Scripts#principles-of-operations > document to help guide contributors along the process of using, creating, and updating resources which are contained within the repository. This community repository will also feature several community members as board members. As part of the board, they will be asked to help maintain the repository with tasks such as testing and providing feedback on all submitted resources, communicating with other board members in order to approve pull requests, and continuing to be good community advocates of PowerCLI and the community repository. 1.5 PowerCLI Installation Walkthrough VMware PowerCLI 6.5.1 Installation Walkthrough VMware PowerCLI 6.5.1 introduces a new installation method to users. This new method pulls directly from the PowerShell Gallery. This video will walk you through how to uninstall any previous versions of PowerCLI and then install PowerCLI 6.5.1. The video also separates out the process for systems with PowerShell 5.0 or PowerShell 3.0/4.0. Click to see topic media 5
2. vsphere CLI (vcli) vsphere CLI (vcli) is a package of several command sets whose goal is to manage and automate vsphere environments. 6
2.1 vsphere CLI - Overview vsphere CLI (vcli) is one of VMware s command line interfaces (CLI). However, vcli is actually a package of several command sets instead of being one itself. It is a great, free, tool whose goal is to manage and automate vsphere environments. It has evolved to be quite versatile over the releases. vcli can be installed on many Windows and Linux operating system (OS) offerings, provides both an interactive shell and the ability to script against it, and it can perform a wide range of tasks against vcenter Servers, ESXi hosts, VMs, and so forth. The vcli package contains several tools, CLIs, and SDKs (software development kits). vcli includes the Perl SDK, which allow users to run vicfg- based commands. vcli also includes two other CLIs, ESXCLI and Datacenter CLI (DCLI). ESXCLI is a way to manage ESXi hosts while connected to a vcenter Server or ESXi host. DCLI is a way to manage many parts of a vcenter Server environment. Lastly, there are a small set of commands which can be used to manage ESXi hosts. These commands are namely vmkfstools and resxtop. 2.2 Datacenter CLI (DCLI) - Overview An Overview of Datacenter CLI Datacenter Command-Line Interface (DCLI) is one of vsphere s newest CLIs. DCLI works exclusively with the vsphere Automation API (REST API for vsphere) to provide both an interactive and scriptable mode to monitor and manage all features made available to the REST based API. With the vsphere 6.5 release, DCLI has picked up a ton of new functionalities! DCLI can now interact with the vcenter Server Appliance (VCSA), perform VM tasks, receive environmental vsphere information, managing vsphere Tags, and work with the Content Library. This is definitely a great tool to have in the toolbox for anyone accessing a vsphere environment. Accessing DCLI DCLI is able to be installed on a multitude of Windows and Linux systems as part of the vsphere Command-Line Interface (vcli). DCLI is also automatically included within the vcenter Server Appliance (VCSA) as well as being included as part of the installation process for vcenter Server on Windows. Using DCLI There are two ways to use DCLI, either in an interactive shell or via scripting mode. Both methods have their benefits, so it comes down to either preference or what fits the use case at the time. Interactive Shell Scripting Mode Output Formatting DCLI also has the ability to change how the output from commands are handled. The formatter allows users to specify outputs of CSV, HTML, JSON, Simple, Table, or XML. Here s an example of using the formatter by showing a list of the hosts and then specifying the +formatter json parameter to receive the same output in JSON: 7
Credential Store One of the other big capabilities of DCLI is storing credentials with the Credential Store. This streamlines the process of connecting to the same vcenter repeatedly, and even more so when working in scripting mode. The first time a user connects to a vcenter server, they will be prompted to store the credentials to the credstore. After that initial save, the credstore will be referenced with each connection to that server. If needed, credentials can be specified at the command line to over-ride the values stored in the credstore. Users can also work with the credstore to either populate credentials with the +credstore-add +username user parameter, remove credentials with the +credstore-remove +user user +server servername.fqdn, and list what credentials already exist with the +credstore-list parameter. Here s an example output from using the +credstore-list parameter within an interactive mode session: Conclusion DCLI has, relatively, flown under the radar up until this point. Interactive mode allows even brand new users to easily access and run commands within moments of connecting and without knowin the name of the name spaces or reading documentation. Scripting mode lets users have those same great commands available outside of the interactive shell and utilize them in a standalone basis or within a scheduled task or cron job. These commands can easily be used with the formatter option to produce a variety of outputs and allow quick integration into other products. DCLI is a great and intuitive CLI that should be added to anyone s toolbox! For more information on getting started with DCLI, see the DCLI Reference. Originally Posted: VMware vsphere Blog - Getting Started with Datacenter CLI (DCLI) 8
2.3 DCLI - Interactive Mode DCLIs features an interactive shell with several great features. The most noteworthy features are tab complete, session history retention, and the ability to find a namespace just by starting it off with the first few characters. Accessing DCLI s Interactive Shell An example workflow to begin using DCLI s interactive shell: Start DCLI with the following options (Note: options start with a + in DCLI) +server -> The vcenter name/ip to connect to +skip-server-verification -> Instruct DCLI to ignore any certificate warnings +interactive -> Start the interactive mode Once in the interactive shell, users can start working immediately by either using tab to see the namespaces available or by starting to type in the name of the object they would like to begin viewing or working with. The below example below shows a tab complete example when working with VM objects: Another example below shows how to retrieve the VCSA s system version and then how the session history works: As seen in the above example, a user can recall a previously used command line just by typing in the first letter of that prior command. This eliminates the need for users to type in long command lines 9
while adding speed and consistency. The command history will persist through each of the user s sessions as well. 2.4 DCLI - Scripting Mode The scripting mode allows DCLI commands to be used within scripts. These scripts can then be turned into more extensive workflows and/or scheduled tasks. Accessing DCLI s Scripting Mode Calling DCLI commands through the scripting mode is fairly similar to the interactive mode, but a server has to be specified with each command. The full namespace should be referenced as well. Below is an example of retrieving the VCSA s system version followed by retrieving a list of VMs: Example Script Here is an example of a bash script to create 10 VMs on a given datastore, resource-pool and folder: #!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ]; do echo Creating LoopVM$COUNTER dcli com vmware vcenter vm create --name LoopVM$COUNTER --guest "SLES_12_64" -- resource-pool "resgroup-9" --folder "group-v7" --datastore "datastore-12" let COUNTER=COUNTER+1 done bold=$(tput bold) normal=$(tput sgr0) echo ${bold}--- VM List ---${normal} dcli com vmware vcenter vm list 2.5 DCLI - Getting Started Demonstration 10
Getting Started with vsphere's Datacenter Command-Line Interface Here s a demonstration video showing DCLI s interactive mode in action! The video details connecting to a VCSA, entering DCLI s interactive mode, displaying some general environmental information as well as pointing out some of the benefits when using interactive mode, and lastly it creates a VM and shows all the important information about that new VM. Click to see topic media 11