# Variable properties

**URL:** <https://forums.powershell.org/t/variable-properties/11279>\
**Category:** PowerShell Help\
**Created:** [September 7, 2018, 4:13am UTC](https://forums.powershell.org/t/variable-properties/11279 "2018-09-07T04:13:27Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![rzimmerman](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rzimmerman](https://forums.powershell.org/u/rzimmerman)\
**Post date:** [September 7, 2018, 4:13am UTC](https://forums.powershell.org/t/variable-properties/11279/1 "2018-09-07T04:13:27Z")

</div>

I’m a newbie at this, forgive the silly question.

I’m reading Learn Windows PowerShell in a Month of Lunches. In the chapter on variables, it is mentioned that variables have properties, such as count, length, and so on. However I cannot see a way to list the properties available. I tried $myvariable | gm, but that certainly doesn’t show the properties.

Can anyone clarify for me?

R

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 7, 2018, 4:28am UTC](https://forums.powershell.org/t/variable-properties/11279/2 "2018-09-07T04:28:53Z")

</div>

It always depends on what’s in your variable.

```
$item = Get-Item -Path C:\Windows\explorer.exe
$item | Get-Member
```
  
Or even more specific:
```
$item | Get-Member -MemberType Property
```
  
Or did you want to see the values of the properties?
```
$item | Select-Object -Property *
```

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [September 9, 2018, 10:19am UTC](https://forums.powershell.org/t/variable-properties/11279/3 "2018-09-09T10:19:33Z")

</div>

Variables themselves don’t have properties; the things a variable contains can have properties. An empty variable won’t generate results from Get-Member, because there’s nothing in the variable for Get-Member to reflect on.

---

<div class="post-metadata">

**Author:** ![dkirkland](https://avatars.discourse-cdn.com/v4/letter/d/258eb7/32.png) [@dkirkland](https://forums.powershell.org/u/dkirkland)\
**Post date:** [September 10, 2018, 2:07pm UTC](https://forums.powershell.org/t/variable-properties/11279/4 "2018-09-10T14:07:17Z")

</div>

Looks like y’all were on top of this one… The variable has to be loaded with something first…

&nbsp;

```
[2:32:32 PM] C:/Scripts> $test = "bob"
[2:32:51 PM] C:/Scripts> $test | gm

   TypeName: System.String

Name MemberType Definition
---- ---------- ----------
Clone Method System.Object Clone(), System.Object ICloneable.Clone()
CompareTo Method int CompareTo(System.Object value), int CompareTo(string strB), int IComparable.CompareTo(System.Object obj), in...
Contains Method bool Contains(string value)
CopyTo Method void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
EndsWith Method bool EndsWith(string value), bool EndsWith(string value, System.StringComparison comparisonType), bool EndsWith(...
Equals Method bool Equals(System.Object obj), bool Equals(string value), bool Equals(string value, System.StringComparison com...
GetEnumerator Method System.CharEnumerator GetEnumerator(), System.Collections.IEnumerator IEnumerable.GetEnumerator(), System.Collec...
GetHashCode Method int GetHashCode()
GetType Method type GetType()
GetTypeCode Method System.TypeCode GetTypeCode(), System.TypeCode IConvertible.GetTypeCode()
IndexOf Method int IndexOf(char value), int IndexOf(char value, int startIndex), int IndexOf(char value, int startIndex, int co...
IndexOfAny Method int IndexOfAny(char[] anyOf), int IndexOfAny(char[] anyOf, int startIndex), int IndexOfAny(char[] anyOf, int sta...
Insert Method string Insert(int startIndex, string value)
IsNormalized Method bool IsNormalized(), bool IsNormalized(System.Text.NormalizationForm normalizationForm)
LastIndexOf Method int LastIndexOf(char value), int LastIndexOf(char value, int startIndex), int LastIndexOf(char value, int startI...
LastIndexOfAny Method int LastIndexOfAny(char[] anyOf), int LastIndexOfAny(char[] anyOf, int startIndex), int LastIndexOfAny(char[] an...
Normalize Method string Normalize(), string Normalize(System.Text.NormalizationForm normalizationForm)
PadLeft Method string PadLeft(int totalWidth), string PadLeft(int totalWidth, char paddingChar)
PadRight Method string PadRight(int totalWidth), string PadRight(int totalWidth, char paddingChar)
Remove Method string Remove(int startIndex, int count), string Remove(int startIndex)
Replace Method string Replace(char oldChar, char newChar), string Replace(string oldValue, string newValue)
Split Method string[] Split(Params char[] separator), string[] Split(char[] separator, int count), string[] Split(char[] sepa...
StartsWith Method bool StartsWith(string value), bool StartsWith(string value, System.StringComparison comparisonType), bool Start...
Substring Method string Substring(int startIndex), string Substring(int startIndex, int length)
ToBoolean Method bool IConvertible.ToBoolean(System.IFormatProvider provider)
ToByte Method byte IConvertible.ToByte(System.IFormatProvider provider)
ToChar Method char IConvertible.ToChar(System.IFormatProvider provider)
ToCharArray Method char[] ToCharArray(), char[] ToCharArray(int startIndex, int length)
ToDateTime Method datetime IConvertible.ToDateTime(System.IFormatProvider provider)
ToDecimal Method decimal IConvertible.ToDecimal(System.IFormatProvider provider)
ToDouble Method double IConvertible.ToDouble(System.IFormatProvider provider)
ToInt16 Method int16 IConvertible.ToInt16(System.IFormatProvider provider)
ToInt32 Method int IConvertible.ToInt32(System.IFormatProvider provider)
ToInt64 Method long IConvertible.ToInt64(System.IFormatProvider provider)
ToLower Method string ToLower(), string ToLower(cultureinfo culture)
ToLowerInvariant Method string ToLowerInvariant()
ToSByte Method sbyte IConvertible.ToSByte(System.IFormatProvider provider)
ToSingle Method float IConvertible.ToSingle(System.IFormatProvider provider)
ToString Method string ToString(), string ToString(System.IFormatProvider provider), string IConvertible.ToString(System.IFormat...
ToType Method System.Object IConvertible.ToType(type conversionType, System.IFormatProvider provider)
ToUInt16 Method uint16 IConvertible.ToUInt16(System.IFormatProvider provider)
ToUInt32 Method uint32 IConvertible.ToUInt32(System.IFormatProvider provider)
ToUInt64 Method uint64 IConvertible.ToUInt64(System.IFormatProvider provider)
ToUpper Method string ToUpper(), string ToUpper(cultureinfo culture)
ToUpperInvariant Method string ToUpperInvariant()
Trim Method string Trim(Params char[] trimChars), string Trim()
TrimEnd Method string TrimEnd(Params char[] trimChars)
TrimStart Method string TrimStart(Params char[] trimChars)
Chars ParameterizedProperty char Chars(int index) {get;}
Length Property int Length {get;}
```

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [September 10, 2018, 3:40pm UTC](https://forums.powershell.org/t/variable-properties/11279/5 "2018-09-10T15:40:12Z")

</div>

Another important thing to understand is what type of data the variable contains, so the properties will be vary for each of these:

```
$bull = "string"
$bull = 1
$bull = 1,2,3
```

That is a true vary a bull. 😛

---

<div class="post-metadata">

**Author:** ![rzimmerman](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rzimmerman](https://forums.powershell.org/u/rzimmerman)\
**Post date:** [September 10, 2018, 4:28pm UTC](https://forums.powershell.org/t/variable-properties/11279/6 "2018-09-10T16:28:15Z")

</div>

Thanks for your replies. However, I still have not been able to find it. Here is the example:

PS C:&gt; $computers[0]  
SERVER-R2  
PS C:&gt; $computer[1]  
SERVER1  
PS C:&gt; $computer[-1]  
localhost  
PS C:&gt; $computer[-2]  
SERVER1

PS c:&gt; $computers.count  
3

OK, I can see that the variable $computers has a count property, but how can I list the other properties it has so I can choose from them?

Thanks again

&nbsp;

&nbsp;

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 10, 2018, 5:40pm UTC](https://forums.powershell.org/t/variable-properties/11279/7 "2018-09-10T17:40:39Z")

</div>

To list the members of an object you simply use [Get-Member](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/get-member?view=powershell-5.1).

```
$computers | Get-Member
```
The alias for **Get-Member** is **gm**.

---

<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:** [September 10, 2018, 8:54pm UTC](https://forums.powershell.org/t/variable-properties/11279/8 "2018-09-10T20:54:38Z")

</div>

format-list or fl is another way. Usually “| fl \*” shows a lot more.

```
$a = get-process terminal
$a | fl
$a | fl *
```

---

<div class="post-metadata">

**Author:** ![rzimmerman](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rzimmerman](https://forums.powershell.org/u/rzimmerman)\
**Post date:** [September 10, 2018, 8:58pm UTC](https://forums.powershell.org/t/variable-properties/11279/9 "2018-09-10T20:58:26Z")

</div>

As I mentioned in my original post, the format $computers | gm does not show me the properties, such as the count property in the example. Here is the output of $computers | gm

PS C:\Users\RogerZ\> $computers | gm

All I get are methods and one property (length).

&nbsp;

&nbsp;

TypeName: System.String

&nbsp;

Name MemberType Definition

* * *

Clone Method System.Object Clone(), System.Object IClon…

CompareTo Method int CompareTo(System.Object value), int Co…

Contains Method bool Contains(string value)

CopyTo Method void CopyTo(int sourceIndex, char destin…

EndsWith Method bool EndsWith(string value), bool EndsWith…

Equals Method bool Equals(System.Object obj), bool Equal…

GetEnumerator Method System.CharEnumerator GetEnumerator(), Sys…

GetHashCode Method int GetHashCode()

GetType Method type GetType()

GetTypeCode Method System.TypeCode GetTypeCode(), System.Type…

IndexOf Method int IndexOf(char value), int IndexOf(char …

IndexOfAny Method int IndexOfAny(char anyOf), int IndexOfA…

Insert Method string Insert(int startIndex, string value)

IsNormalized Method bool IsNormalized(), bool IsNormalized(Sys…

LastIndexOf Method int LastIndexOf(char value), int LastIndex…

LastIndexOfAny Method int LastIndexOfAny(char anyOf), int Last…

Normalize Method string Normalize(), string Normalize(Syste…

PadLeft Method string PadLeft(int totalWidth), string Pad…

PadRight Method string PadRight(int totalWidth), string Pa…

Remove Method string Remove(int startIndex, int count), …

Replace Method string Replace(char oldChar, char newChar)…

Split Method string Split(Params char separator), s…

StartsWith Method bool StartsWith(string value), bool Starts…

Substring Method string Substring(int startIndex), string S…

ToBoolean Method bool IConvertible.ToBoolean(System.IFormat…

ToByte Method byte IConvertible.ToByte(System.IFormatPro…

ToChar Method char IConvertible.ToChar(System.IFormatPro…

ToCharArray Method char ToCharArray(), char ToCharArray(i…

ToDateTime Method datetime IConvertible.ToDateTime(System.IF…

ToDecimal Method decimal IConvertible.ToDecimal(System.IFor…

ToDouble Method double IConvertible.ToDouble(System.IForma…

ToInt16 Method int16 IConvertible.ToInt16(System.IFormatP…

ToInt32 Method int IConvertible.ToInt32(System.IFormatPro…

ToInt64 Method long IConvertible.ToInt64(System.IFormatPr…

ToLower Method string ToLower(), string ToLower(culturein…

ToLowerInvariant Method string ToLowerInvariant()

ToSByte Method sbyte IConvertible.ToSByte(System.IFormatP…

ToSingle Method float IConvertible.ToSingle(System.IFormat…

ToString Method string ToString(), string ToString(System…

ToType Method System.Object IConvertible.ToType(type con…

ToUInt16 Method uint16 IConvertible.ToUInt16(System.IForma…

ToUInt32 Method uint32 IConvertible.ToUInt32(System.IForma…

ToUInt64 Method uint64 IConvertible.ToUInt64(System.IForma…

ToUpper Method string ToUpper(), string ToUpper(culturein…

ToUpperInvariant Method string ToUpperInvariant()

Trim Method string Trim(Params char trimChars), stri…

TrimEnd Method string TrimEnd(Params char trimChars)

TrimStart Method string TrimStart(Params char trimChars)

Chars ParameterizedProperty char Chars(int index) {get;}

Length Property int Length {get;}

---

<div class="post-metadata">

**Author:** ![ilikecheese](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@ilikecheese](https://forums.powershell.org/u/ilikecheese)\
**Post date:** [September 10, 2018, 9:42pm UTC](https://forums.powershell.org/t/variable-properties/11279/10 "2018-09-10T21:42:09Z")

</div>

I believe the Count property is just like an alias for Lentgh property. You are correct that it doesn’t specifically show “Count” as one of the listed properties when you pipe your variable to Get-Member, but you do see Length property at the bottom of your list. There’s not much else that is not visible which is I believe what you were really trying to ask originally. If you’re wondering what else is there that you cannot see, one thing you can try is to view your variable in the ISE rather than the console. The intellisense will autosuggest a list of properties when you type the period in $computers.

---

<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:** [September 10, 2018, 10:24pm UTC](https://forums.powershell.org/t/variable-properties/11279/11 "2018-09-10T22:24:04Z")

</div>

Here is a snippet I pulled together a while back to always have handy when looking stuff like this up. Maybe you’ll find this useful.

```
# Get parameters, examples, full and Online help for a cmdlet or function

# Get a list of all functions
Get-Command -CommandType Function | 
Out-GridView -PassThru -Title 'Available functions'

# Get a list of all commandlets
Get-Command -CommandType Cmdlet | 
Out-GridView -PassThru -Title 'Available cmdlets'

# Get a list of all functions for the specified name
Get-Command -Name '*ADGroup*' -CommandType Function | 
Out-GridView -PassThru -Title 'Available named functions'

# Get a list of all commandlets for the specified name
Get-Command -Name '*ADGroup**' -CommandType Cmdlet | 
Out-GridView -PassThru -Title 'Available named cmdlet'

# get function / cmdlet details
(Get-Command -Name Get-ADUser).Parameters
Get-help -Name Get-ADUser -Examples
Get-help -Name Get-ADUser -Full
Get-help -Name Get-ADUser -Online

Get-Help about_*
Get-Help about_Functions

# Find all cmdlets / functions with a target parameter
Get-Command -CommandType Function | 
Where-Object { $_.parameters.keys -match 'credential'} | 
Out-GridView -PassThru -Title 'Available functions which has a specific parameter'

Get-Command -CommandType Cmdlet | 
Where-Object { $_.parameters.keys -match 'credential'} | 
Out-GridView -PassThru -Title 'Results for cmdlets which has a specific parameter'

# Get named aliases 
Get-Alias | 
Out-GridView -PassThru -Title 'Available aliases'

# Get cmdlet / function parameter aliases
(Get-Command Get-ADUser).Parameters.Values | 
where aliases | 
select Name, Aliases | Out-GridView -PassThru -Title 'Alias results for a given cmdlet or function.'

# All Help topics locations
Get-Help about* | Select Name, Synopsis

Get-Help about* | 
  Select-Object -Property Name, Synopsis |
  Out-GridView -Title 'Select Topic' -OutputMode Multiple |
  ForEach-Object {
    Get-Help -Name $_.Name -ShowWindow
  }

explorer "$pshome\$($Host.CurrentCulture.Name)"

# Get any .NET types and their static methods from PowerShell. 
# Enumerate all that are currently loaded into your AppDomain.
#  
[AppDomain]::CurrentDomain.GetAssemblies() | 
foreach { $_.GetTypes() } | 
foreach { $_.GetMethods() } | 
where { $_.IsStatic } | 
select DeclaringType, Name | 
Out-GridView -PassThru -Title '.NET types and their static methods'

# Best Practices

PowerShell scripting best practices
'https://blogs.technet.microsoft.com/pstips/2014/06/17/powershell-scripting-best-practices'

The Unofficial PowerShell Best Practices and Style Guide
https://blogs.technet.microsoft.com/pstips/2014/06/17/powershell-scripting-best-practices

Using PSScriptAnalyzer to check your PowerShell code for best practices
```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [September 11, 2018, 12:24am UTC](https://forums.powershell.org/t/variable-properties/11279/12 "2018-09-11T00:24:14Z")

</div>

If it’s for you just about the porperty **count** try this:

```
Get-Member -InputObject $computers
```
😉

---

<div class="post-metadata">

**Author:** ![rzimmerman](https://avatars.discourse-cdn.com/v4/letter/r/e480ec/32.png) [@rzimmerman](https://forums.powershell.org/u/rzimmerman)\
**Post date:** [September 11, 2018, 12:26am UTC](https://forums.powershell.org/t/variable-properties/11279/13 "2018-09-11T00:26:01Z")

</div>

Thank you. The ISE trick is pretty useful, as are the snippets. I’ll have to dig deeper to see if I can uncover the aliases for the properties. It just seemed strange to me that if a bunch of properties existed as the author said, that there is only one property shown.

Thanks for all your help.

&nbsp;

---

<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:34pm UTC](https://forums.powershell.org/t/variable-properties/11279/14 "2024-05-16T20:34:30Z")

</div>


