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()
2 responses to “PowerShell – Determine possible values for an attribute”