Monday, October 14, 2013

Powershell Tips : Use Only Powershell V2 cmdlets , with PowershellV3 Installed.

 

I use Windows 7 (64 bit) with Powershell V3 installed on it. Most of our users are still on PowerShell v2, Sometime when I am writing scripts for them i use some PowerShell v3 cmdlets accidently.

Normally I write the initially version of all scripts on PowerShell console and I do test my all script in the console only.

So I thought there must be a way to run PowerShell.exe with Version 2 only.

I found the solution and i thought I should share it with You.

It’s simple, Just run “Powershell.exe –Version 2” and this will open a PowerShell console with V2 cmdlets only.

Let’s test it.

When i run $PSVersionTable  in my PowerShell console, you can see that  my PSversion is 3.0.

14-10-2013 17-07-33

Now lets run “Powershell.exe –Version 2” .

14-10-2013 16-46-57

and new PowerShell console will open and let’s check it’s $PSVersionTable.

You can see that this PowerShell version of this console is 2.0.

14-10-2013 17-07-59

Now let’s check one more thing.  Let’s see if version 2 is having Version 3.0 cmdlets or not (just to make our self bit  more confident).

Let’s search for all cmdlets those has the word Update. The Version 3 has a new cmdlet named “Update-Help”.

Get-Command *update* -CommandType cmdlet

14-10-2013 17-08-23

and then run the same command on v2 PowerShell console.

You can check that , Update-Help cmdlet is not available on V2 console :)

14-10-2013 17-08-55

Now i can use it and create a V2 script more confidentiality, without worrying of using v3 cmdlets accidentally. . :) 

Note: I tested this on Windows 7 (64 bit) with PowerShell v3 installed.

Thanks for reading and your time,.

Thanks

Aman Dhally

clip_image001 clip_image002 clip_image003 clip_image005  clip_image007

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.