PowerShell 3 quick switch to PowerShell 2

PowerShell 3 improves on PowerShell 2 by adding almost 500 new cmdlets built-in.  One drawback unfortunately, is cmdlets or scripts written for version 2 do not always work as expected.

If you need to quickly switch to version 2 while you are in PowerShell 3 type the following.

PowerShell.exe -version 2

You will see the copyright info change to 2009 and if you type get-host it will display version 2.

image

To switch back to version 3 you can either  close and re-open PowerShell or simply type in your current session

PowerShell.exe -version 3

image

Advertisements

Set PowerShell icon launch to default to run as Administrator

Many commands in PowerShell will not run unless they are run as an administrator.  You can of coarse right click on the taskbar icon and choose the ‘Run as Administrator’ option. But if you prefer to have the icon or shortcut default to run PowerShell as Administrator then you can right click on it once, and choose the ‘Properties’ item.

image

In the window that pops up, near the bottom right of the window click  the ‘Advanced’ button.

image

On the next (and last) screen, you will see a checkbox with ‘Run as administrator’. make sure that checkbox is selected, click ‘OK’, then ‘OK’ on the main Properties window to exit .

image

From now on out, when you click the PowerShell icon, it will run as administrator and you should see the Administrator prefix displayed in the PowerShell title bar.

image

Get memory configuration of all vm’s on hyper-v server and output to text file

Two line powershell script that gets memory configuration of all vm’s and outputs to text file.  Change path and name of vmmemory.txt to suit your needs.

Works on Server 2012 with powershell 3

Get-VM | Get-VMMemory | out-file -filepath C:\VMMemory.txt
C:\VMMemory.txt 

Get all vm’s on a hyper-v server and output to text file

This two line PowerShell script will get all vm’s on a hyper-v server and output to text file. Change path and name of vmrunning.txt to suit your needs.

Works on Server 2012 with powershell 3

Get-VM | Where-Object {$_.State -eq ‘Running’} | out-file -filepath C:\VMrunning.txt
C:\VMrunning.txt

Powershell 3 combo installers

These combo installers will update PowerShell to Version 3 on either Windows 7 x86 or Windows 7 x64 / Server 2008 R2

The installer runs silently and installs both the dotNetFx40_Full_x86_x64.exe  and either the Windows6.1-KB2506143-x86.msu or Windows6.1-KB2506143-x64.msu files. When the script  completes a pop-up prompting for a reboot will be displayed.

1-28-2013 2-17-52 AM

  After re-booting and launching powershell type get-host to display the version number.

1-28-2013 2-25-39 AM

Windows Explorer MRU (most recently used) clear search powershell script

This one line powershell script will clear the Windows Explorer MRU (most recently used) search list.

The downloaded zip file also includes both the ps1 script and a compiled exe (executable) version of the script for those who want to run it without launching powershell or if you want to place the exe in your windows start-up folder to clear the search entries each time you start windows.  It works on Vista, Windows 7 or windows 8 and server 2008 or 2012. Getting to your startup folder in Windows 8 or Server 2012 requires browsing to the  location below

C:\Users\<User Profile folder name>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Windows Management Framework 3.0 “This update is not applicable to your computer” error

Windows Management Framework 3.0 (Includes PowerShell 3.0, WMI & WinRM for downlevel Win7, 2008, & 2008 R2) is now available here http://www.microsoft.com/en-us/download/details.aspx?id=34595.  For those getting a “This update is not applicable to your computer” error when trying to install it

Update your  Microsoft .Net Framework 4 first. Get it here http://www.microsoft.com/en-us/download/details.aspx?id=17851

After the update the install should complete fine.