MS Power shell All About-

Window Powershell – VMware ESXI- Management CMDLET-

MSPowershellWhat is  PowerShell?

Powershell is Microsoft’s newest scripting language
focused on providing administrators with an easy and
powerful way to perform certain tasks. PowerShell is
either included or can be downloaded and installed on
the following operating systems:

 

powershell

Supported Environments:,Window 7, Windows 8.1 and Windows 2K8 and 2K12.

II. Powershell 4.0 or 5.0 DownloadRequired:
Powershell 4 or 5 Download Reference

i. Powershell 5. 

Windows Management Framework (WMF) 5.0 Preview April 2015 contains functionality that has been updated from WMF 4.0. WMF 5.0 Preview April 2015 is available for installation on Windows 8.1, Windows Server 2012 R2, Windows Server 2012, Windows 2008 R2 and Windows 7, and contains updated versions of the following features:

ii. OS and Service Pack Requirements:

Operating System Service Pack Level Editions
Windows 8.1 All
Windows Server 2012 R2 All except IA64
Windows Server 2012 All except IA64
Windows Server 2008 R2 SP1 All except IA64
Windows 7 SP1

1II. Installing PowwerShell on Windows Platform- For this demonstration, we will install Powershell 5.0 on windows 7 Professional SP1. Workstation Edition.

a. Download (Powershell 4 or 5 Download Reference) and Install Powershell 5.0 on Workstation Platform. 

*Illustrates which Power shell versions specific to the Server 2k(8 and 12) or Workstation(7 sp1 or 8.1) Platform Environment.

powershell1

powershell2

*Please note – click here will ease any download issue specific to client workstation web browsers pop up blocker 

 

b. Copy Windows61.-KB2908075-x64.msu locally on the workstation client and open. 

powerinstall5.01

c. Click Yes to continue with installation.

power5install2

d. Click I agree with EULA to proceed with installation.

powershell5install2*installation in progress- Restart workstation 

powershell5install3II. Open PowerShell – Search Powershell in windows search –

a.Right Click on Windows Powershell -Run As Administrator.

searchpowershellrunpowershellrunasadminb.  Enable Poweshell Script Execution

Note: As a security precaution remote PowerShell scripts cannot be executed unless you enable it. This is required before VMware commands can be executed.

 Powershell Execution Policy Values:

Restricted- This is the default settings. It doesn’t allow profile script to be loaded or script to run

AllSigned – All Scripts and profiles must be digitally signed using a code -signed certificate from a trusted certification authority. This also applies to scripts created and executed on the local system/

RemoteSigned-All scripts or profile files downloaded from the internet must be digitally signed this also applied to scripts from network shares.

Unrestricted- All profile files and scipts will be executed regardless of origin.

i. Type in the Powershell CommandLine: set-ExecutionPolicy RemoteSigned.

powershellremotesingedII. Type Y =(Yes) to allow to change the exution policy to set-ExcutionPolicy Remotesigned.

III. Install the Vmware Powershell ComponentsSnap-Ins and Modules

*Please notes there are 2 main ways to extend the shell,  we will be add snap in method. 

Modules – A package that contains Windows PowerShell commands int he form of functions, cmdlerts and workflows, in addition it may contain variables, aliases and providers. Modules can be written in PowerShell and/or compiled as DLLs.

Snap-Ins – Are compiled cmdlets in to a DLL written in a .Net language are being deprecated and no longer recommended as the way to create and package new cmdlets.

Install the VMware PowerShell Components  by Installing  the Wmware ‘PowerCLI’ onto your local PC that contains the VMware software management objects and Cmdlets

*Reference Install PowerCLI  Section- if have not install PowerCLI before.

IV. Registrered – PSSnapin – Vmware.Automation Cmdlets- Open the VMware (not Windows) PowerShell-  Type- Get-Command -Noun PSSnapin.

a. PS C:\> get-command -noun pssnapin components.
PSSnapinregistred

b. PS C:\> Add-PSSnapin VMware.VimAutomation.Core 

c.  PS C:\> help vm illustrate all Vmware.VIMAutomation.Core CMDLETS

addpsnapinmoduleD: Import-modules:

Copy powershell Modules to local machine  and navgiate to directoy.. Type import-module .\<module file name>

PS C:\scripts\InfraTools\PowerCLIBook\PowerCLIBook> Import-Module .\PowerCLIBook.psd1

VERBOSE: Importing function ‘Add-DistributedSwitchVMHost’.
VERBOSE: Importing function ‘Backup-MsSqlDatabase’.
VERBOSE: Importing function ‘Backup-VcConfig’.

For example below modules are 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.

 * will importing all above modules*

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

Get-Module -ListAvailable

getmoduleliset

  • 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

powerclibook1To view the comamnds specific to Distributed Switches:

Get-Command *DistributedSwitch*

getmoduleliset32To 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

D. Test Vmware Powershell CMDLET – Open the VMware (not Windows) PowerShell
Command Prompt and type the following:

1. Connection to Vcenter or ESXI Host : Syntax Example

Connect-VIServer -Server
<vCenterIPAddress> -User
<adminUsername> -Password <password>

PS C:\> Connect-VIServer -Server mvp-vs01.mvp.local

connectesxhostviapowershell

2.  User and Password Prompt- Input Vcenter or ESXI User ID and Password. 

powershelluseridpromptesxi

*Unsigned Certificate haven’t been configured then see a warning- This can be ignored. 

3. User Successful Authenticated to ESXI or Vcenter. 

ESXI- User Root 

ESXIrootuserauthenicationsuccesfully

 

Vcenter-Domain User-

powershellvcenter1

4.  List Vmware CMDLET- Typing help VM:

*Notice there more option; Click Spacebar to more of the Vmware CMDLET.

listvmcmdletpowershell Sample of Example Commands:

PowerShell Command= Action
Start-VM <guestVMname> =Power on the VM specified
ShutDown-VMGuest <guestVMname> =Shuts down Guest OS
Get-DRSRule –Cluster <ClusterName>=Displays DRS rules for specified cluster
Note: All commands above are entered as one line

6. Execute  a VMware CMDLET, For example, power up a VM guest on ESXI host/Vcenter.

PS C:\> start-VM mvp-sccm02 on ESXI Host.

startvmhostpowershell2 startvmhostpowershell3Start VM on Vcenter Host:

startingvumserver.

Vcenter Rcent Taskstarvumserver01Post Successfully Start VM host

 

startvmcmdlet

* You will see VM host PowerState, Number CPUs , Memory GB status in Powershell Windows

7.  Disconnect from vCenter or ESX
Once finished, it is good practice to disconnect. To do
this type the following command:
Disconnect-VIServer

C:\WINDOWS\system32\
windowspowershell\v1.0\powershell.
exe -PSConsoleFile “C:\Program
Files\VMware\Infrastructure\VSphere
PowerCLI\vim.psc1” -NoExit –Command

Note: The command above is entered as one line

Don’t forget you still must connect to a vCenter Server
or ESX Host so the first command might look like this:
C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe -PSConsoleFile “C:\Program
Files\VMware\Infrastructure\VSphere PowerCLI\vim.psc1”

-NoExit –Command Connect-VIServer
-Server <vCenterIPAddress> -User
<adminUsername> -Password <password>
Note: The command above is entered as one line

Likewise a PowerShell script named C:\My1stPSscript.ps1 can be called by typing:

C:\WINDOWS\system32\
windowspowershell\v1.0\powershell.
exe -PSConsoleFile “C:\Program
Files\VMware\Infrastructure\VSphere
PowerCLI\vim.psc1” -NoExit –Command
C:\MyFirstPSscript.ps1
Note: The command above is entered as one line

 

V. Summary

The basics of VMware PowerShell commands has a wealth of information on
PowerShell scripting between the integration of VMware and Microsoft
tools- with with a number of sample scripts.

listvmcmdletpowershell

For example: Let say you need to a VM guest network configuration

PS C:\> get-VMGuestNetworkInterface mvp-sccm01.mvp.local

References:

1. Microsoft PowerShell How Install.
Microsoft PowerShell How Install

2.VMware PowerShell Components Download and
Documentation.
https://www.vmware.com/support/pubs/ps_pubs.html

3. Vmware Powershell Compoenets Install Guide:
https://www.vmware.com/support/developer/windowstoolkit/wintk40/doc/viwin_install.pdf

4. PowerCLI book author has written and introduction to get you up to speed –
http://www.simple-talk.com/sysadmin/powershell/an-introduction-to-powershell-modules/

VI. NetApp PowerShell cmdlets(coming soon!!)

Download the DataONTAP.zip from NetApp site
http://community.netapp.com/t5/Microsoft-Cloud-and-Virtualization-Discussions/Data-ONTAP-PowerShell-Toolkit-3-2/td-p/93081

2. Extract the content folder DataONTAP.

 

3. Copy the DataONTAP folder to the following location: C:\Windows\System32\WindowsPowerShell\v1.0\Modules

4. Launch the PowerShell window and type the following command. Confirm ‘Yes’ when prompted.

Set-ExecutionPolicy unrestricted

5. Type another command to import the NetApp DataOntap modules in PowerShell:

image

6. Its done! You can confirm by running below command. It will list all the NetAPP cmdlets available

Get-Command -module DataONTAP

Import Vmware CMDLET Modules Guide

Scope: This posting is show overview import Vmware Powershell CMDLET  to manage Vmware environment.

Introduction:

CMDLET Modules have primarily 2 locations on your system:

Cmdlets (also pronounced it “command-let”) are probably the most obvious feature when comparing Powershell to other scripting language. A cmdlet is a small, self contained piece of functionality that does one specific job.

For example: Get-command | Where {$_.pssnapin -like “Microsoft.p*.”}). count

The Get-Command generates a list Powershell commands and list is piped in a filter 

..(Where is the an alias or shorthand for where-object) that accepts those commands installed by a Powershell snapin. The method of extending powershell whose names start Microsoft P. Then count the number of commands in the filerterd list. As illustrated in Figure #1.

Figure#1.
PS C:\Users\ (Get-Command |where {$_.pssnapin -like “Microsoft.p*” } ).count
60

powershellgetcommand

Cases and Operators:
The operator -like is used to perform the comparison in the Figure#1- For example,  

All cmd-lets has a verb-noun syntax. It starts with verb. The second part is a nount that describes what the verb is actingin on – in this case.

Get-Command with -Noun and -Verb

As you get to know PowerShell better so you become familiar with verbs such as ‘Set’ or ‘Get’ and nouns such as ‘Process’ or ‘Computer’.  This is why I now prefer to filter Get-Command with -Noun or -Verb.  One of my greatest successes was finding ‘Restart-Service’.  I had used start and stop-service, but when I tried this filter I unearthed the useful Restart-Service.

# PowerShell Get-Command Nouns
Clear-Host
Get-Command -Noun Service

Also Verbs

# PowerShell Get-Command Nouns
Clear-Host
Get-Command -Verb S*

Note 2: I could have chosen -Verb Set, but I wanted to show you that -Verb also take wildcards*.

Get-Command -Module

Firstly list your modules with Get-Module.  Make your selection, for example, ISE.

# PowerShell Get-Command Module info
Clear-Host
Get-Module ISE

Here is another example which imports a modules then checks the cmdlets.

$Baskets = “PSDiagnostics”
Import-Module $Baskets
Get-Command -Module $Baskets

Reference:
Powershell cmdlet Verb-Noun 
https://technet.microsoft.com/en-us/library/dd315315.aspx

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 module name exact folder structure– module\module folder name\module name(same)

modulespwoershellsCreate folder under Module level —> Module Folder name then put module psd1 under it.

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:

listednewlyimportedmodules

H: Get-Member

Get-Member is best described as the Swiss Army Knife of Powershell. It seems be the one tool for which I’m always leverage.  Help File for Get-Member. Type Get-Help to display it. Get-Member retrieves information about objects. Powershell cmdles return objects, so we use Get-Member to view those objects.

Listing the Properties and Methods of a Command or Object

Any time you’re writing scripts or working from the command line the biggest problem you face is this: how do I know what I can and cannot do? How do I know which properties and methods are available to me? How can I actually write a script or type a command-line command without having to memorize every object model found on MSDN?

One way to do that is to use the Windows PowerShell Get-Member cmdlet. Once you connect to an object you can pipe that object to Get-Member; in turn, Get-Member will enumerate the properties and methods of that object. For example, suppose you’d like to know which properties and methods are available for event logs. Assuming you know that Get-EventLog -list will retrieve an event log object, all you need to do is issue this command:

Get-EventLog -list | Get-Member

In turn, Windows PowerShell will report back data similar to this:

Name                      MemberType Definition
----                      ---------- ----------
add_Disposed              Method     System.Void add_Disposed(EventHandler v...
add_EntryWritten          Method     System.Void add_EntryWritten(EntryWritt...
BeginInit                 Method     System.Void BeginInit()
Clear                     Method     System.Void Clear()
Close                     Method     System.Void Close()

Interested in the properties of the WMI Win32_BIOS class? Then use this command, tacking on the -membertype parameter in order to limit returned data to properties:

Get-WmiObject win32_bios | Get-Member -membertype properties

And, yes, setting -membertype to methods returns just the methods.

Here’s an interesting use of Get-Member. Did you know that some of the properties returned by the Get-Process cmdlet have aliases? Well, you would if you ran this command, setting -membertype to AliasProperty:

Get-Process | Get-Member -membertype aliasproperty

Here’s what you get back:

Name    MemberType    Definition
----    ----------    ----------
Handles AliasProperty Handles = Handlecount
Name    AliasProperty Name = ProcessName
NPM     AliasProperty NPM = NonpagedSystemMemorySize
PM      AliasProperty PM = PagedMemorySize
VM      AliasProperty VM = VirtualMemorySize
WS      AliasProperty WS = WorkingSet

What does it mean for a property to have an alias? That simply means that the next time you work with the Get-Process cmdlet you can type NPM rather then NonpagedSystemMemorySize. For example:

Get-Process | Select-Object name, npm

And, yes, Get-Member does work with COM objects as well. Need to know the properties and methods of the FileSystemObject? All you have to do is use the New-Object cmdlet to create an instance of the FileSystemObject and then pipe that object to Get-Member:

New-Object -com scripting.filesystemobject | Get-Member

Here’s the type of information you’ll get back:

Name                MemberType Definition
----                ---------- ----------
BuildPath           Method     string BuildPath (string, string)
CopyFile            Method     void CopyFile (string, string, bool)
CopyFolder          Method     void CopyFolder (string, string, bool)
CreateFolder        Method     IFolder CreateFolder (string)
CreateTextFile      Method     ITextStream CreateTextFile (string, bool, bool)
DeleteFile          Method     void DeleteFile (string, bool)
DeleteFolder        Method     void DeleteFolder (string, bool)
DriveExists         Method     bool DriveExists (string)
FileExists          Method     bool FileExists (string)
FolderExists        Method     bool FolderExists (string)

Get-Member to view object properties

PS> Get-Process c* | Get-Member -Member Type Property | form -Wide -Colum 2

PS C:\Users\richard> Get-Process c* | Get-Member -memberType Property | format-Wide
-Column 2
Getmember1
  Get-PSDrive-
  Get-PSDRive displays information about the providers that are currently installed. Full details

Get-PSDrive

Gets drives in the current session.

Aliases

The following abbreviations are aliases for this cmdlet:

  • gdr

Syntax

Parameter Set: Name
Get-PSDrive [[-Name] <String[]> ] [-InformationAction <System.Management.Automation.ActionPreference> {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend} ] [-InformationVariable <System.String> ] [-PSProvider <String[]> ] [-Scope <String> ] [-UseTransaction] [ <CommonParameters>]

Parameter Set: LiteralName
Get-PSDrive [-LiteralName] <String[]> [-InformationAction <System.Management.Automation.ActionPreference> {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend} ] [-InformationVariable <System.String> ] [-PSProvider <String[]> ] [-Scope <String> ] [-UseTransaction] [ <CommonParameters>]
 Language features
Powershell works as a scripting language as well as an interactive shell. All scripting language needs to be able to perform a common set of actions:
  • Store data-variable and arrays
  • Repeat actions-loops
  • Control logic flow -branches
  • Reuse sections of code–functions
  • Output results.
As we get into loops and branching, you’ll see that there’s a common structure to many powershell commands:
command(condition)(script block of actions)
Variables
A variable is a store for data that’ll be used during the execution of a script. What can a variable store?
Powershell has a number of predefined variables-
TBA.
  • 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

III. 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 *