There are a few modules and PSSnapin I always like to use with PowerShell.  My initial setup and customization is not complicated at all but sometimes I forget what the profile.ps1 needs and path to use for profile.ps1 file.

My setup consists of 3 main things.

  1. Additional PS-Snapins
  2. Modules
  3. Profile.ps1 to load environment.

The place I like to use for profile.ps1 is %windir%\system32\WindowsPowerShell\v1.0\profile.ps1 because this applies to all users.  If you don't want the profile loading for ALL users then maybe use: %UserProfile%\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

The contents of the profile.ps1 only contain the following:

Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
Add-PSSnapin -Name Quest.ActiveRoles.ADManagement
Add-PSSnapin -Name VMware.VimAutomation.Core
Import-Module 'see full path below\virtualmachinemanagercore.psd1'
Import-module bsonposh
Import-Module ActiveDirectory

Full path for virtualmachinemanagercore.psd1 is:

'C:\Program Files\Microsoft System Center 2012\Virtual Machine Manager\bin\psModules\virtualmachinemanagercore\virtualmachinemanagercore.psd1'

You can add more PSSnapin or modules if needed but these are the ones I use the most.  Save this file to preferred location mentioned above and that's it.

I only mention the following because I see it asked a lot.  In order for the PSSnapin and Module commands in the profile.ps1 file to work you must first install the necessary components.  For modules you simply copy the folder/files to:

  • %windir%\system32\WindowsPowerShell\v1.0\

For PSSnapin you must download the application from vendor and install.

UPDATE - PSSnapin's are slowly going away.  The preferred method is for developers to provide Modules.  Case in point starting with PowerCLI 6.0 VMware is transitioning to Modules.  You can read more here:

http://blogs.vmware.com/PowerCLI/2015/03/powercli-6-0-introducing-powercli-modules.html

To add the new PowerCLI 6.0 or newer add the following to your Environment Variable PATH.

C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\"

And the following to your $PROFILE.

Import-Module VMware.VimAutomation.Common
Import-Module VMware.VimAutomation.Core
Import-Module VMware.VimAutomation.Storage

There are other modules for things like vRealize Automation or Distributed Switches but the above are the most common.