Wednesday, December 20, 2006

Useful .NET stuff

One of the big advantages of PowerShell is the easy access to .NET
For instance, in order to gain access to the .NET functionality contained in datatime we
can use Get-Member to look at the available methods:

$a = [datetime]
Get-Member -InputObject $a -s

Or written in a shorter notation:

[datetime] | gm -s

We might find the IsLeapYear or Parse methods interisting, and decide to try them out:

[datetime]::Parse("2008/02/29 012:23:45")

What? January 29th? Maybe 2008 is a leapyear? Try this:

[datetime]::IsLeapYear(2008)

Another interesting part of .NET might be math . Lets use it to round the number 9876.54321 to one decimal:

[math]::round(9876.54321,1)

Other interesting uses for .NET:

[datetime]::now.addminutes(-1000000) #give me datetime 1 million minutes ago)
[console]::title = "My PoweShell window" #sets the title of the current console window

No comments: