Vmware Powershell CMDLET Modules

Import Vmware CMDLET Modules Guide

Scope: This posting illustrates an overview how to Import Vmware Powershell CMDLET  to manage Vmware environment.

Introduction:

CMDLET Modules have primarily 2 locations on your system:

Default location
%windir%\system32\WindowsPowerShell\Modules this is the location for system wide modules available to any user in the system.

User Level
%USERPROFILE%\Documents\WindowsPowerShell\Modules

C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShel
l\v1.0\Modules\

Each module is stored in a folder where there is a psd1 file that is known as a Module Manifest, powermaifeastmodulesvsphere6

getmodulelisetmodulesvsphere6aThese manifest has the settings for the module and sets the restrictions for it in terms of .Net Framework version, version of PowerShell, files to load, version, copyright, author and many other settings.

This file can load what is called a main module and sub-modules each can either be a psm1 or dll file, in addition they can also be scripts that gets processes. As it can be seen using modules provide great flexibility in terms of formats and structure.

We can also have modules in other locations that can be accessed by the PowerShell session we run in, the locations are defined in the environment variable :$env:PSModulePath

Example

C:\> $env:PSModulePath

* C:\Users\<Vmware Admin User>\Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\Modules\

C:\Users\richard\Documents\WindowsPowerShell\modules;C:\Windows\system32\WindowsPowerShell\Modules\

If we want to add another path for PowerShell to look at we just add that path to the current environment variable:

By using the following setting:

$env:psmodulepath = $env:psmodulepath + “;”

To list the modules that are available we use the Get-Module cmdlet withe the -listavailable parameter:

Get-Module -ListAvailable

2.  Download Vmware Powershell Modules:

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.

Vmpowerclicmdlet.psm1-The Powersehll module manifest file,The PowerShell module file containing the functions which make up the  module within  VMware.VimAutomation.Core.

I. Import Vmware CMDLET Modules Guide

1. Set Default  the CMDLET Modules Path location by typing the environment variable :$env:PSModulePath

A. Copy CMDLET psm1 files to CMDLET Module User Path (C:\Users\richard\Documents\WindowsPowerShell\modules(Reference CMDLET psm1 download)

powermaifeastB. Open Powershell as Administrator-—> Type; $env:PSModulePath check the default module environment Path Location:

environpathSyntax: PS C:\> $env:PSModulePath

Output Default Environment Path: “C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShel
l\v1.0\Modules\”

C. Add User Profile Modules to existing Environment Powershell Path:

Syntax: $env:psmodulepath = $env:psmodulepath + “;”

Example adding user path  C:\Users\richard\Documents\WindowsPowerShell\modules to default Powershell Environment Path:

PS C:\> $env:psmodulepath = $env:psmodulepath + “C:\Users\richard\Documents\WindowsPowerShell\modules;C:\Windows\system32\WindowsPowerShell\Modules\”
PS C:\>custompowershelldefaultenvironmentpowershelldefaultenvironmentOutput Default Environment Path with added custom environment path:

PS C:\> $env:PSModulePath
C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShel
l\v1.0\Modules\C:\Users\richard\Documents\WindowsPowerShell\modules;C:\Windows\system32\WindowsPowerShell\Modules\C:\Users\richard\Documents\WindowsPowerShell\modules;C:\Windows\system32\WindowsPowerShell\Modules\

D. List all the Modules—–> Typing:
PS C:\> get-module -ListAvailable

listmodules*Notice you didn’t see none of the below modules there?

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.

Vmpowerclicmdlet.psm1-The Powersehll module manifest file,The PowerShell module file containing the functions which make up the  module within  VMware.VimAutomation.Core.

* You much create the exact file path as the psm1 file within the path..

For example—-> All about module must reside under exact folder name :

PowerCLIBook.psd1 – The PowerShell module manifest file, which describes the contents of the module and controls how the module is processed.

  • C:\Users\richard\Documents\WindowsPowerShell\modules\PowerCLIBook<module same as the upper level>

powerclifilepath*Make sure you match the module name exact to the folder structure- For example the  module has to be exact as the module folder name:

Example: create folder same name as DistributeSwitch, PowerCLIBook, and vmwarepowerclicmdlet. psm1. Copy all associate to the associate folder names.

modulespwoershellsOnce you move all files to it’s associate folder names you should only see 3 folders. 

modulesfoldersF: Import Module- Type import-module <Module Folder>

Syntax:
PS C:\> Import-Module PowerCLIBook -Verbose

PowerCLIBook Modules
importmodulepowerclibook
VERBOSE: Importing function ‘Evacuate-VMHost’.
VERBOSE: Importing function ‘Export-Folders’.
VERBOSE: Importing function ‘Export-PermissionsToCSV’.
VERBOSE: Importing function ‘Export-VMLocation’.
VERBOSE: Importing function ‘Export-Xls’.
VERBOSE: Importing function ‘Get-ADUserObject’.
VERBOSE: Importing function ‘Get-AggregationJobs’.
VERBOSE: Importing function ‘Get-ClusterSummary’.
VERBOSE: Importing function ‘Get-DistributedSwitch’.
VERBOSE: Importing function ‘Get-DistributedSwitchCandidate’.
VERBOSE: Importing function ‘Get-DistributedSwitchNetworkAdapter’.
VERBOSE: Importing function ‘Get-DistributedSwitchPortGroup’.
VERBOSE: Importing function ‘Get-DistributedSwitchPrivateVLAN’.
VERBOSE: Importing function ‘Get-FolderPath’.
VERBOSE: Importing function ‘Get-FolderStructure’.
VERBOSE: Importing function ‘Get-IPPool’.
VERBOSE: Importing function ‘Get-LicenseKey’.
VERBOSE: Importing function ‘Get-MissingPortgroups’.
VERBOSE: Importing function ‘Get-Network’.
VERBOSE: Importing function ‘Get-OvfDetails’.
VERBOSE: Importing function ‘Get-SnapshotCreator’.
Vmware VDS Module
importmoduleVDS
PS C:\> Import-Module DistributedSwitch -Verbose
VERBOSE: Importing function ‘Add-DistributedSwitchVMHost’.
VERBOSE: Importing function ‘Get-DistributedSwitch’.
VERBOSE: Importing function ‘Get-DistributedSwitchCandidate’.
VERBOSE: Importing function ‘Get-DistributedSwitchNetworkAdapter’.
VERBOSE: Importing function ‘Get-DistributedSwitchPortGroup’.
VERBOSE: Importing function ‘Get-DistributedSwitchPrivateVLAN’.
VERBOSE: Importing function ‘Get-VMHostPnic’.
VERBOSE: Importing function ‘New-DistributedSwitch’.
VERBOSE: Importing function ‘New-DistributedSwitchNetworkAdapter’.
VERBOSE: Importing function ‘New-DistributedSwitchPortGroup’.
VERBOSE: Importing function ‘New-DistributedSwitchPrivateVLAN’.
VERBOSE: Importing function ‘New-VMHostNetworkAdapter’.
VERBOSE: Importing function ‘Remove-DistributedSwitch’.
VERBOSE: Importing function ‘Remove-DistributedSwitchNetworkAdapter’.
VERBOSE: Importing function ‘Remove-DistributedSwitchPortGroup’.
VERBOSE: Importing function ‘Remove-DistributedSwitchPrivateVLAN’.
VERBOSE: Importing function ‘Remove-DistributedSwitchVMHost’.
VERBOSE: Importing function ‘Set-DistributedSwitch’.
VERBOSE: Importing function ‘Set-DistributedSwitchNetworkAdapter’.
VERBOSE: Importing function ‘Set-DistributedSwitchPortGroup’.
VERBOSE: Importing function ‘Set-DistributedSwitchVMHost’.

InfraTools
importmoduleinfratools
PS C:\> Import-Module infraTools -Verbose
VERBOSE: Importing function ‘Get-SyslogInfo’.
VERBOSE: Importing function ‘Get-VMCreationDate’.
VERBOSE: Importing function ‘Get-VMdisk’.
VERBOSE: Importing function ‘Get-VMEvents’.
VERBOSE: Importing function ‘Get-VMStat’.
VERBOSE: Importing function ‘Set-VMdisk’.

 

G: List Module Recently Imported:

listednewlyimportedmodulesIII. References:

A. PowerCLIBook
http://www.powerclibook.com/?p=137B. Windows Powershell Moduleshttps://msdn.microsoft.com/en-us/library/dd878324%28v=vs.85%29.aspx

B. Vmware PowerCLI Blog
http://blogs.vmware.com/PowerCLI/tag/powercli-modules

C. Infra Tools Modules
https://psvmware.wordpress.com/


Leave a Reply

Your email address will not be published. Required fields are marked *