Jul 16 2008

Powershell and .NET

Category: Software DevelopmentDmitry @ 6:55 pm

PowershellPowershell gives you full access to Microsoft .NET framework objects. There is a special syntax for accessing static methods and properties (it uses square brackets). For creating new objecects and instantiating .NET classes you use Net-Object commandlet.

Accessing static methods and properties:

[class]::method(arg1, arg2 …)
[class]::SomeProp

Instantiating objects and accessing their methods and properties:

$obj = New-Object Foo.Bar
$obj.method(arg1, arg2 …)
$obj.PropName

or shorter (anonymous var way):

(new-object Foo.Bar).method(arg1, arg2 …)

(new-object Foo.Bar).PropName

Some of the libraries are not accessible in powershell until you load them:

[Reflection.Assembly]::LoadWithPartialName(”System.Windows.Forms”)

Getting More Help

To find out more about net-object, use the “man” page (manual):

Or you could have typed “get-help new-object” (man is just an alias to it)

Tags: , , ,

One Response to “Powershell and .NET”

  1. Recent URLs tagged Powershell - Urlrecorder says:

    [...] recorded first by wao1201 on 2008-08-27→ Powershell and .NET [...]

Leave a Reply