Rss Feed Tweeter button
VMware vSphere PowerCLI Reference
14Apr/115

PowerCLI Book: Download Scripts, Functions and Modules

This book is obviously full of a tonne of PowerCLI examples for you to use - naturally though you will not want to type them all out from the book yourself after reading them! So each script and function is available for download on a per chapter basis from the Resources and Downloads section of the book's home on the Sybex website http://www.sybex.com/go/vmwarevspherepowercliref .

Whilst this could be handy if you want to use a few or even just one function from a chapter, there are 23 chapters worth of files to download if you want everything. So we have combined all the functions into a single PowerShell module from which you have access to everything. If you are not familiar with PowerShell modules yet PowerCLI book author Jonathan has written and introduction to get you up to speed - http://www.simple-talk.com/sysadmin/powershell/an-introduction-to-powershell-modules/.

However, to start using the PowerCLIBook module this is what you need to do:

  • Extract the zip file and copy the PowerCLIBook folder containing the 4 files that make up the module to your PowerShell modules file location, typically this will be C:\Users\username\Documents\WindowsPowerShell\Modules

 

The module is made up of four files:

  • PowerCLIBook.psd1 - The PowerShell module manifest file, which describes the contents of the module and controls how the module is processed.
  • PowerCLIBook.psm1 - The PowerShell module file containing the functions which make up the PowerCLIBook module.
  • DistributedSwitch.psm1 - The PowerShell module file containing the functions which make up the DistributedSwitch nested module, if you like a sub-module of the PowerCLIBook module.
  • Test-Version.ps1 - A script which is run prior to the PowerCLIBook module being called which checks to see if PowerCLI 4.1 or newer is installed.

 

  • From your PowerShell session you will now be able to see that the PowerCLIBook Module is available:

Get-Module -ListAvailable

  • To use functions from the module it needs to be imported into the current session:

Import-Module PowerCLIBook

  • To view what functions are now available (in total there are 79!):

Get-Command -Module PowerCLIBook

  • To view the comamnds specific to Distributed Switches:

Get-Command *DistributedSwitch*

  • To get help on one of the functions:

Get-Help Set-DistributedSwitch -Detailed

  • To view the help examples for a function

Get-Help Set-DistributedSwitch -Examples

We hope you find this a useful way to access the scripts and functions from the book.

Comments (5) Trackbacks (1)
  1. For PowerShell newcomers, consider updating this to explain how to ‘unblock’ zip/script files downloaded from the Internet. And maybe a general blog post (if the book doesn’t cover it) on PowerShell execution policies (and 32-bit vs 64-bit consoles).

  2. Is it allowed to discuss about these functions and ask for suggestions in the powercli forum?

    regards

    Andreas

  3. To have the modules load for every PowerCLI session automatically, create a file called Microsoft.PowerShell_profile.ps1 at C:\Users\username\Documents\WindowsPowerShell

    Enter the following lines in the file and save it

    Import-Module “C:\Users\username\Documents\WindowsPowerShell\Modules\PowerCLIBook\PowerCLIBook.psm1″
    Import-Module “C:\Users\username\Documents\WindowsPowerShell\Modules\PowerCLIBook\DistributedSwitch.psm1″

    Restart PowerCLI and you should have access to the functions in these modules.

    Regards
    Ossie


Leave a comment

(required)