PowerShell Scripts, Tips, Expert Advices, Forums, and Resources

Geek Sync Live

Welcome to PowerShell.com, the educational and community site for Windows PowerShell People. Get a quick overview.

As a Powershell.com member you will have access to:

  • Daily PowerShell tips written by Microsoft MVPs and other leading Windows PowerShell experts
  • Free Windows PowerShell advice and training provided by Microsoft MVPs and other leading Windows PowerShell experts
  • Access to leading Windows PowerShell blogs
  • A free ebook, Mastering PowerShell, written by Microsoft MVP Dr. Tobias Weltner
PowerTip of the Day

Identifying Essential Add-Type Statement

When you access .NET types and objects directly in your PowerShell code, you must make sure that the appropriate .NET assemblies are loaded. If you do not, you risk that your script will break once it runs in a simple PowerShell console.

Here is a way how you can find out the names of the assemblies required for objects and types in use. This would tell you what the assembly name is for the object stored in $window variable:

$window = New-Object -TypeName System.Windows.Window

And this is how you find the assembly name for types:



Once you know the assembly name, make sure you add a statement like this before you use the objects or types:

Add-Type -AssemblyName PresentationFramework

Twitter This Tip! ReTweet this Tip!

Copyright 2012 PowerShell.com. All rights reserved.