# Finding the properties of a .NET class

**URL:** <https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701>\
**Category:** PowerShell Help\
**Created:** [June 12, 2019, 10:26am UTC](https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701 "2019-06-12T10:26:55Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![replicant](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/replicant/32/213_2.png) [@replicant](https://forums.powershell.org/u/replicant)\
**Post date:** [June 12, 2019, 10:26am UTC](https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701/1 "2019-06-12T10:26:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [June 12, 2019, 10:29am UTC](https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701/2 "2019-06-12T10:29:21Z")

</div>

Here you go.

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

---

<div class="post-metadata">

**Author:** ![replicant](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/replicant/32/213_2.png) [@replicant](https://forums.powershell.org/u/replicant)\
**Post date:** [June 12, 2019, 12:24pm UTC](https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701/3 "2019-06-12T12:24:52Z")

</div>

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”](https://docs.microsoft.com/en-us/dotnet/api/system.environment?view=netframework-4.8). Is that possible?

Thanks.

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [June 12, 2019, 12:48pm UTC](https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701/4 "2019-06-12T12:48:33Z")

</div>

gotcha !

**[System.Environment].DeclaredProperties.Name**

---

<div class="post-metadata">

**Author:** ![replicant](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/replicant/32/213_2.png) [@replicant](https://forums.powershell.org/u/replicant)\
**Post date:** [June 12, 2019, 12:56pm UTC](https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701/5 "2019-06-12T12:56:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![js2010](https://avatars.discourse-cdn.com/v4/letter/j/ebca7d/32.png) [@js2010](https://forums.powershell.org/u/js2010)\
**Post date:** [June 12, 2019, 1:32pm UTC](https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701/6 "2019-06-12T13:32:57Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [June 12, 2019, 4:09pm UTC](https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701/7 "2019-06-12T16:09:18Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:32pm UTC](https://forums.powershell.org/t/finding-the-properties-of-a-net-class/12701/8 "2024-05-16T20:32:09Z")

</div>


