Finding the properties of a .NET class

I’d like to write some PS code that will loop through the available elements in the [Environment] class, e.g.: Is64BitProcess, Is64BitOperatingSystem, etc.

At the prompt, I can see the list appear if I type “[Environment]::” followed by a dot. How can I fetch those values in a loop? I tried:

foreach ($item in [Environment]::) { $item }

But that fails with the “missing property name” error.

Here you go.

[Environment] | Get-Member -MemberType Prop* |Select-Object -ExpandProperty Name

Hi kvprasoon,

I’m actually looking for the list of fields maintained in the Environment class (e.g. CommandLine, CurrentDirectory, etc.). The complete list can be found at the first link returned from a Google search of “Environment Class”. Is that possible?


gotcha !


Perfect! Works like a charm. Thank you very much.

Don’t know why it was closed, Check this out. Looping through static properties.

$obj = [environment]
$obj | get-member -Static -MemberType property | foreach name | 
  foreach { "$_ = $($obj::$_)" }

CommandLine = powershell
CurrentDirectory = c:\users\js
CurrentManagedThreadId = 10
ExitCode = 0
HasShutdownStarted = False
Is64BitOperatingSystem = True
Is64BitProcess = True
MachineName = MYCOMP
NewLine =

OSVersion = Microsoft Windows NT 10.0.16299.0
ProcessorCount = 4
StackTrace = blah blah blah...
SystemDirectory = C:\WINDOWS\system32
SystemPageSize = 4096
TickCount = 1457532187
UserDomainName = MYCOMP
UserInteractive = True
UserName = js
Version = 4.0.30319.42000
WorkingSet = 107544576

The assumption is that the OP decided it should be, since it solved his use case, or one of the moderators.

There are other ways to get this stuff, because we know PS offers many ways to do so, but what was presented was the most succinct with respect to the OP case.