Assemblies loaded in PowerShell

A question in the newsgroups about using Windows Forms with PowerShell got me thinking about what assemblies are actually loaded by PowerShell.  As I load a number of extra snapins in my profile I decided to step through them and see what extras are loaded

Starting with a pure PowerShell load with no extras we get this

PS> Get-PSSnapin

Name        : Microsoft.PowerShell.Core
PSVersion   : 1.0
Description : This Windows PowerShell snap-in contains Windows PowerShell management cmdlets used to manage components
              of Windows PowerShell.

Name        : Microsoft.PowerShell.Host
PSVersion   : 1.0
Description : This Windows PowerShell snap-in contains cmdlets used by the Windows PowerShell host.

Name        : Microsoft.PowerShell.Management
PSVersion   : 1.0
Description : This Windows PowerShell snap-in contains management cmdlets used to manage Windows components.

Name        : Microsoft.PowerShell.Security
PSVersion   : 1.0
Description : This Windows PowerShell snap-in contains cmdlets to manage Windows PowerShell security.

Name        : Microsoft.PowerShell.Utility
PSVersion   : 1.0
Description : This Windows PowerShell snap-in contains utility Cmdlets used to manipulate data.

PS> [appdomain]::currentdomain.getassemblies() | sort -property fullname | format-table fullname

Microsoft.PowerShell.Commands.Management, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.PowerShell.Commands.Utility, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.PowerShell.ConsoleHost, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Microsoft.PowerShell.Security, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Configuration.Install, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.DirectoryServices, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Management, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
System.Management.Automation, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35
System.Xml, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089

The loaded assemblies are split between the PowerShell and System namespaces.

These next sections will only show the additions in order to highlight what is changing. The listings will show the name of the snapin and the additional assemblies loaded by that snapin.

Adding the PowerShell Community Extensions

Name        : Pscx
PSVersion   : 1.0
Description : PowerShell Community Extensions (PSCX) base snapin which implements a general purpose set of cmdlets.

ICSharpCode.SharpZipLib, Version=, Culture=neutral, PublicKeyToken=1b03e6acf1164f73

Pscx, Version=, Culture=neutral, PublicKeyToken=null
Pscx.Core, Version=, Culture=neutral, PublicKeyToken=null

PowerGadgets adds a significant number of assemblies

Name        : PowerGadgets
PSVersion   : 1.0
Description : Generates Charts, Gauges and Maps Gadgets from Windows PowerShell data

Accessibility, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
ChartFX.Designer, Version=7.0.1500.0, Culture=neutral, PublicKeyToken=a1878e2052c08dce
ChartFX.WinForms, Version=7.0.2568.19404, Culture=neutral, PublicKeyToken=a1878e2052c08dce
ChartFX.WinForms.Base, Version=7.0.2568.19286, Culture=neutral, PublicKeyToken=a1878e2052c08dce

PowerGadgets.Commands, Version=1.0.1500.0, Culture=neutral, PublicKeyToken=a1878e2052c08dce
PowerGadgets.Data, Version=1.0.1500.0, Culture=neutral, PublicKeyToken=a1878e2052c08dce

System.Drawing, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089

including Windows Forms as shown.

PowerPad also adds Windows Forms assemblies

Name        : PowerPad
PSVersion   : 1.0
Description : This PowerPad snap-in contains cmdlets to edit and run PSH code snippets.

PowerPad, Version=, Culture=neutral, PublicKeyToken=null

System.Drawing, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

System.Windows.Forms, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089

Note that PowerPad doesn’t supply a Public Key Token signifying that it hasn’t a strong name

The free sdmgpo cmdlets just add their own assemblies

Name        : get-sdmgpo
PSVersion   : 1.0
Description : Lists a GPO (or all GPOs) in an AD domain and their properties

get-SDMgpo, Version=, Culture=neutral, PublicKeyToken=null

Name        : new-sdmgpo
PSVersion   : 1.0
Description : Let’s you create new GPOs in a domain

new-SDMgpo, Version=, Culture=neutral, PublicKeyToken=null

Quest ADcmdlets again just adds its own assembly

Name        : Quest.ActiveRoles.ADManagement
PSVersion   : 1.0
Description : Registers the CmdLets and Providers in this assembly

Quest.ActiveRoles.ArsPowerShellSnapIn, Version=, Culture=neutral, PublicKeyToken=null

Finally the OneNote provider

Name        : Microsoft.Office.OneNote
PSVersion   : 1.0
Description : Provides cmdlets for managing OneNote notebooks.

Microsoft.Office.Interop.OneNote, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c
Microsoft.Office.OneNote.Commands, Version=, Culture=neutral, PublicKeyToken=null

Note the interop assenmbly that is being loaded.  This eanbles access to the OneNote COM objects through .NET code.

If you really want to know what is being loaded on to your system then you need to use


[appdomain]::currentdomain.getassemblies() | sort -property fullname | format-table fullname

The first command shows the PowerShell snapins that have been loaded and the second shows the .NET assemblies that those snapins load into PowerShell.  Knowing this will help when deciding why a particular piece of .NET functionality can’t be accessed.

Technorati Tags: ,

This entry was posted in Powershell. Bookmark the permalink.

4 Responses to Assemblies loaded in PowerShell

  1. Pingback: Understanding .NET from the perspective of an IT Professional « Energized About Technology

  2. Joseph Uher says:

    Richard: This old post helped me considerably to view the assemblies I have loaded in powershell. It verifies that the SMOExtended is also loaded. I am working on Server2003, SQL Server 2008, Powershell 1.0. The problem is that my code executes correctly with output from the command line; it fails when I run from script. I simply cannot see where my error is, and would deeply appreciate your help.

    First, the error:
    Cannot find an overload for “Server” and the argument count: “2”.
    At C:\Powershell\Scripts\Script-Database_01.ps1:50 char:29
    + $source = new-object <<<< ("$my.Server") $DataSource
    + CategoryInfo : InvalidOperation: (:) [New-Object], MethodException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

    Now, the code (when run from cmd line, I copy/paste everything between PROCESS{ and }:
    function Script-Database_01 {
    # Created: 09/06/2013
    # Edited: 09/06/2013

    HelpMessage="Local directory to save build-scripts output.")]
    [string[]] $Filepath,

    HelpMessage ="Server or instance name.")]
    [string[]] $DataSource,

    HelpMessage="The database to be scripted.")]
    [string[]] $DatabaseName
    Write-Output $Filepath
    Write-Output $DataSource
    Write-Output $DatabaseName
    # Set 'Option Explicit' to catch subtle errors:
    set-psdebug -strict

    # Stop on fatal error:
    $ErrorActionPreference ="stop"

    #Load SMO assembly, and SMOExtended and SQLWMIManagement libraries:
    $ms = "Microsoft.SqlServer"
    $v = [System.Reflection.Assembly]::LoadWithPartialName("$ms.SMO")
    [appdomain]::currentdomain.getassemblies() | sort -property fullname | format-table fullname

    [System.Reflection.Assembly]::LoadWIthPartialName("$ms.SMOExtended") | out-null
    [appdomain]::currentdomain.getassemblies() | sort -property fullname | format-table fullname

    $my = "$ms.Management.SMO"
    $source = new-object("$my.Server") $DataSource
    if ($Source.Version -eq $null) {Throw "Cant find the instance $DataSource."}

    $db = $source.Databases[$DatabaseName]
    if ($ -ne $DatabaseName) {Throw "Cant find the database '$DatabaseName' in $DataSource."}

    $transfer = new-object("$my.Transfer") $db
    $transfer.Options.ScriptBatchTerminator = $true # This only goes to file
    $transfer.Options.ToFileOnly = $true # This only goes to file
    $transfer.Options.Filename = "$($Filepath)\$($DatabaseName)_Build_01b.sql"

    # Do it:

  3. Pingback: Assemblies loaded in PowerShell | Richard Siddaway’s Blog | Sladescross's Blog

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s