RSS

PowerShell – Determine possible values for an attribute

09 Mar

While working on a script for XenApp 6.5 I wanted to perform actions based on the session state. To me however, the possible state values were not clear.

Without knowing these states, I would have to make assumptions which could lead to unexpected behavior and results.

Generic example

Since not everyone is using Citrix, here’s a more generic sample using Get-EventLog to determine the possible values for attribute EntryType

1. Get-EventLog -LogName System | Select EntryType -First 1 | Get-Member

This resulted in:

   TypeName: Selected.System.Diagnostics.EventLogEntry

Name        MemberType   Definition
—-        ———-   ———-
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
EntryType   NoteProperty System.Diagnostics.EventLogEntryType EntryType=Information

2.  Enumerate the values using:
[Enum]::GetValues(‘System.Diagnostics.EventLogEntryType‘)

This results in the following possible values:

Error
Warning
Information
SuccessAudit
FailureAudit

XenApp 6.5 example

To determine the possible states, I did the following:

1. Get-XASession | Select State | Get-Member

This resulted in:

TypeName: Selected.Citrix.XenApp.Commands.XASession

        Name        MemberType   Definition
—-        ———-   ———-
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
State       NoteProperty Citrix.XenApp.Commands.SessionConnectionState State=Disconnected

2.  Enumerate the values using:
[Enum]::GetValues(‘Citrix.XenApp.Commands.SessionConnectionState‘)

This results in the following possible values:

Unknown
Active
Connected
Connecting
Shadowing
Disconnected
Idle
Listening
Resetting
Down
Initializing
Stale
Licensed
Unlicensed
Reconnected

Alternative method for PowerShell 3.0 / .NET Framework 4.0 and later

After writing this blog post I came across this post http://www.powershellmagazine.com/2013/03/15/pstip-getting-enum-values-in-powershell-3-0/ explaining an alternative method that is available for PowerShell 3.0 / .NET Framework 4.0 and later :

[System.Diagnostics.EventLogEntryType ].GetEnumValues()

[System.Diagnostics.EventLogEntryType].GetEnumNames()

 

 

Advertisement
 
2 Comments

Posted by on March 9, 2016 in Citrix, Microsoft, Powershell, XenApp

 

Tags: , , , , ,

2 responses to “PowerShell – Determine possible values for an attribute

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: