While talking with Hal and Jonathan on the PowerScripting podcast, I was asked the question “What is .NET?” Of course, I mentioned that it’s a framework, but then I choked… the .NET Framework is a huge thing to try to tackle like that, especially when talking with IT pros. Being a developer and working with the .NET framework, I can tell you it’s a collection of libraries that have a whole lot of code that we don’t have to write and can use to make our developing a lot easier. However, I didn’t need to get into it as a developer and needed to suppress the developer speak.

What is the .NET Framework?

When I say that the .NET framework is huge, I’m referring to how much it covers – be it web services, web applications and websites, desktop applications, or yes, even shell scripts. There are libraries – collection of objects and commands – to make it easy to access data, manage configurations, work with accessibility and assistive technologies, address security concerns… just to name a few things that you can do.

What is .NET Framework in terms of PowerShell?

Sean Kearney, a.k.a. The Energized Tech, recently wrote a post titled Understanding .NET from the perspective of an IT Professional. In that post, he talks of assemblies, which developers are quite familiar with. If you have to support developers and they happen to ask you which assemblies are installed on your machine, you could use this:

[appdomain]::CurrentDomain.GetAssemblies() | Select FullName

This command will list all of the assemblies in the current domain. Each assembly listing includes the name, version, culture, and public key token; these fields are key to developers as they need to use those lines when configuring their .NET projects that may live on your server.

The output may look something like this:

PresentationFramework, Version=, Culture=neutral,

If you want to work with an assembly that isn’t loaded by default, you could use the Add-Type cmdlet in PowerShell 2.0. For example, let’s say we’re writing a script that gets a computer’s NetBIOS name, the logged-in user’s user name, and the domain. These can easily be accessed by System.Windows.Forms.SystemInformation. To see these details, run the following commands:

Add-Type -AssemblyName System.Windows.Forms

And as suggested by Aleksandar Nikolic, here’s a good way to see what static properties and methods belong to the SystemInformation class:

[System.Windows.Forms.SystemInformation] | Get-Member - Static

As you can see, you can use these .NET assemblies from within PowerShell, as PowerShell is built on top of the .NET Framework.

If you have questions about Add-Type, I’d first recommend checking out:

Get-Help Add-Type -examples

Learning More

As I mentioned, the .NET Framework is huge enough to have its own podcast. You can find out more about .NET in the community through the .NET Rocks! podcast, hosted by Carl Franklin and Richard Campbell (one of the co-hosts of the IT pro sister show called RunAs Radio).

Someone else listening to the podcast suggested reading MSDN. My advice – just be familiar with the MSDN Library and how to search it as needed. You’ll find this to be a great resource, especially if you’re going to write your own custom compiled cmdlets, providers, and binary modules.

This was just a high level overview of what the .NET Framework can do. If you want to see more things you can do with the .NET Framework, check out some of the fun projects over at Coding4Fun!

Matt and I want to hear what you’ve thought about the series so far. Leave us comments on our posts or get in touch with us. I can be emailed at sarah at codinggeekette dot com.

Special thanks to Aleksandar Nikolic for catching the typo in this entry. The Add-Type command has been updated.

One thought on “PowerShell Not Your Father’s Command Line Part 28 of 31: What is the .NET Framework?

  1. A code article and starts to acknowledge that ITPros can make use of .Net framework through PowerShell. But how does an ITPro without a developer background start to use MSDN and understand terminology such as static, override, []::Something? The examples on MSDN are good but closest thing to PowerShell are the C examples and these still can’t be used as is.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.