Jun 102013

Run this to reduce the load time of your Powershell windows when using the Powershell add-ons.
You will need to run this for both 32 and 64bit powershell environments.
You will also need to run this each time you install a new version of PowerCLI.
The window may take a few minutes to complete.

Launch a 64 and 32bit powershell window and runAS an Administrator.
Paste this into each window. 

Set-Alias ngen (Join-Path ([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()) ngen.exe)

Get-ChildItem -Path $env:SystemRoot\assembly\GAC_MSIL\VimService*.XmlSerializers |
ForEach-Object {
if ($_) {
$Name = $_.Name
Get-ChildItem -Path $_
} |
Select-Object -Property @{N=”Name”;E={$Name}},@{N=”Version”;E={$_.Name.Split(“_”)[0]}},@{N=”PublicKeyToken”;E={$_.Name.Split(“_”)[-1]}} |
ForEach-Object {
if ($_) {
ngen install “$($_.Name), Version=$($_.Version), Culture=neutral, PublicKeyToken=$($_.PublicKeyToken)”

May 312013

I’ve found that the Powershell Window performace is limited unless you make some changes.
Below are some quick things you can do to increase the performance and hopefully reduce the time of your script execution.

-  This command will check and set the Max Memory that each Powershell session can use.
Default is 150MB:
Get-item WSMan:\localhost\Shell\MaxMemoryPerShellMB
Set-item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1024 -Force

-  This command, added to your script, will run garbage colection and free up some RAM.

- It was found that Windows Tasks will launch your Powershell scripts at “Below Normal” CPU priority.
This is how you can fix that issue.  Its a pain but VERY worth it if you use Windows Tasks to launch your scripts.
Step1 – Export your Task to an XML file.
-   schtasks /query /tn “\MyTask” /xml > “c:\temp\MyTask.xml”
Step2 – Edit the XML file (Notepad works) and change this part “<Priority>4</Priority>”
-  You should see that the orginal is set to a value of 7.  Setting it to 4 makes a world of difference.
Step3 – Import the XML back into the Tasks window.
- Within Task Scheduler, right click the folder you want the task to live and select “Import Task.”
- Browse to your file, Click Open, edit your task as needed and save  it