There have been some debate regarding when to use .net namespaces within PowerShell. Some people will call .net classes all the time just because they are used to write in C#, C++, etc. Just keep in mind the code you write most likely will be used by other people, so be conscious about your audience. But as a good rule of thumb I do this.
- Try to write with the PowerShell cmdlets available
- If there are not cmdlets for what I want to do, then I use the CIM classes
- Finally use .NET
However, every rule has an exception and in the next couple of years is going to become the rule. When managing large scale systems or dealing with a lot of data PowerShell may not be an efficient tool to handle those tasks.
Let me give you a quick example
If i need to write all the numbers between 1 and 10,000 to a file I would do something like this
Using cmdlets this process will take around 96 seconds
Now let’s see how long the same process will take using the .net namespace system.io
As you can see with .net system.io namespace it only took 0.31 seconds. There is a 95 seconds difference between PowerShell and .Net.
I am not saying go start writing everything in .Net but keep in mind when dealing with scale you may need to start looking into it