Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
January 23, 2024

Finding Your Way on the System.IO.Path

Since we’ve been exploring ways to use .NET classes to supplement existing command coverage in PowerShell, I thought we should explore the System.IO namespace. Here, you will find several classes to incorporate into your PowerShell scripting. As you’ll see, some of the classes provide functionality already offered by existing cmdlets. I always recommend using cmdlets in your code wherever possible for beginner scripters. Cmdlets are easier to understand, are documented, and provide features like -WhatIf that you don’t get when accessing the .NET Framework directly.

You can turn to the .NET Framework when you need to bridge a gap, such as providing a cross-platform solution. Or if you need to eke out a bit more performance. Using cmdlets always implies a little bit of overhead in the trade-off for the cmdlet’s benefits. For the majority of readers, this overhead is negligible and not worth worrying about.

System.IO is the top-level namespace. We don’t access this directly. Instead, we’re going to look at a class one level down, System.IO.Path. This class is included in a core PowerShell class.

PS C:\> [System.Reflection.Assembly]::GetAssembly([System.IO.Path]) 

GAC    Version        Location
---    -------        --------
False  v4.0.30319     C:\Program Files\PowerShell\7\System.Private.CoreLib.dll
Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.