Behind the PowerShell Pipeline logo

Behind the PowerShell Pipeline

Subscribe
Archives
January 11, 2024

Environmental Impact

Let’s continue our exploration of using the [System.Environment] class from the .NET Framework. As I explained last time, there is no way to construct an instance of this class, so we must use the static (::) operator to get properties and invoke methods.

PS C:\> [Environment]::Version

Major  Minor  Build  Revision
-----  -----  -----  --------
8      0      0      -1

PS C:\> [Environment]::GetEnvironmentVariable("OS")
Windows_NT

Today, I want to focus on a few methods I think you’ll find useful.

PS C:\> Get-TypeMember System.Environment -MemberType Method | Format-List Name,ReturnType,Syntax 

Name       : Equals
ReturnType : System.Boolean
Syntax     : $obj.Equals([Object]obj)

Name       : Exit
ReturnType : System.Void
Syntax     : $obj.Exit([Int32]exitCode)

Name       : ExpandEnvironmentVariables
ReturnType : System.String
Syntax     : $obj.ExpandEnvironmentVariables([String]name)

Name       : FailFast
ReturnType : System.Void
Syntax     : {$obj.FailFast([String]message), 
             $obj.FailFast([String]message,[Exception]exception)}

Name       : GetCommandLineArgs
ReturnType : System.String[]
Syntax     : $obj.GetCommandLineArgs()

Name       : GetEnvironmentVariable
ReturnType : System.String
Syntax     : {$obj.GetEnvironmentVariable([String]variable),
             $obj.GetEnvironmentVariable([String]variable,
             [EnvironmentVariableTarget]target)}

Name       : GetEnvironmentVariables
ReturnType : System.Collections.IDictionary
Syntax     : {$obj.GetEnvironmentVariables([EnvironmentVariableTarget]target), 
             $obj.GetEnvironmentVariables()}

Name       : GetFolderPath
ReturnType : System.String
Syntax     : {$obj.GetFolderPath([SpecialFolder]folder), 
             $obj.GetFolderPath([SpecialFolder]folder,[SpecialFol...

Name       : GetHashCode
ReturnType : System.Int32
Syntax     : $obj.GetHashCode()

Name       : GetLogicalDrives
ReturnType : System.String[]
Syntax     : $obj.GetLogicalDrives()

Name       : GetType
ReturnType : System.Type
Syntax     : $obj.GetType()

Name       : SetEnvironmentVariable
ReturnType : System.Void
Syntax     : {$obj.SetEnvironmentVariable([String]variable,[String]value), 
             $obj.SetEnvironmentVariable([String]variable,[String]value,
             [EnvironmentVariableTarget]target)}

Name       : ToString
ReturnType : System.String
Syntax     : $obj.ToString()
Want to read the full issue?
GitHub Bluesky LinkedIn About Jeff
Powered by Buttondown, the easiest way to start and grow your newsletter.