5 March 2018

Environment class with PowerShell


Getting information about the local Windows installation and some simple info on the physics is usually done through Windows environmental variables.  There is a somewhat old blog post (link) on the subject from the Microsoft PowerShell Team.

But using the .NET Environment class gives you a lot more than the environmental variables.

This is some examples of usage of the static elements of the Environment class:

[System.Environment]::CommandLine

[System.Environment]::CurrentDirectory

[System.Environment]::CurrentManagedThreadId

[System.Environment]::ExitCode

[System.Environment]::HasShutdownStarted

[System.Environment]::Is64BitOperatingSystem

[System.Environment]::Is64BitProcess

[System.Environment]::MachineName

[System.Environment]::NewLine

[System.Environment]::OSVersion | Format-List -Property *

[System.Environment]::ProcessorCount

[System.Environment]::StackTrace

[System.Environment]::SystemDirectory

[System.Environment]::SystemPageSize

[System.Environment]::TickCount

[System.Environment]::UserDomainName

[System.Environment]::UserInteractive

[System.Environment]::UserName

[System.Environment]::Version | Format-List -Property *

[System.Environment]::WorkingSet

[System.Environment]::Equals($null, $true)

[System.Environment]::Exit(42)

[System.Environment]::ExpandEnvironmentVariables('%ComSpec%')
[System.Environment]::ExpandEnvironmentVariables('%Path%').Split(';')

[System.Environment]::FailFast('Boom!')

[System.Environment]::GetCommandLineArgs()

[System.Environment]::GetEnvironmentVariable('ComSpec')

[System.Environment]::GetEnvironmentVariables(


[System.Enum]::GetNames([System.Environment+SpecialFolder])[System.Environment]::GetFolderPath('SystemX86') | Get-ChildItem

[System.Environment]::GetFolderPath([System.Environment+SpecialFolder])


[System.Environment]::GetLogicalDrives()[0]

[System.Environment]::ReferenceEquals($null, $true)



When I find some new details this will be updated.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.