# Get-System.EnvorinmentStaticProperties1.ps1
# This script demonstrates the static properties on System.Environment
# Thomas Lee - tfl@psp.co.uk
#
# Get and display statics in system.environment class
"Static properties in [System.Environment]"
[System.Environment] | Get-Member -Static -MemberType properties
# Now display the values of the simple static properties
"";"Static Property values for [System.Environment]"
"CommandLine: : {0}" -f [System.Environment]::CommandLine
"CurrentDirectory : {0}" -f [System.Environment]::CurrentDirectory
"ExitCode : {0}" -f [System.Environment]::ExitCOde
"HasShutdownStarted : {0}" -f [System.Environment]::HasShutdownStarted
"MchineName : {0}" -f [System.Environment]::MachineNam
"NewLine : {0}" -f [System.Environment]::NewLine
"OSVersion : {0}" -f [System.Environment]::OSVersion
"ProcessorCount : {0}" -f [System.Environment]::ProcessorCount
"SystemDirctory : {0}" -f [System.Environment]::SystemDirectory
"TickCount : {0}" -f [System.Environment]::TickCount
"UserDomainName : {0}" -f [System.Environment]::UserDomainName
"UserInteractive : {0}" -f [System.Environment]::UserInteractive
"UserName : {0}" -f [System.Environment]::UserName
"Version : {0}" -f [System.Environment]::Version
"WorkingSet : {0}" -f [System.Environment]::WorkingSet
# Here is the stack trace:
"";"StackTrace:"
[System.Environment]::StackTrace
This script produces the following output:
PS C:\foo> Get-System.EnvironmentStaticProperties.ps1'
Static properties in [System.Environment]
TypeName: System.Environment
Name MemberType Definition
---- ---------- ----------
CommandLine Property static System.String CommandLine {get;}
CurrentDirectory Property static System.String CurrentDirectory {get;set;}
ExitCode Property static System.Int32 ExitCode {get;set;}
HasShutdownStarted Property static System.Boolean HasShutdownStarted {get;}
MachineName Property static System.String MachineName {get;}
NewLine Property static System.String NewLine {get;}
OSVersion Property static System.OperatingSystem OSVersion {get;}
ProcessorCount Property static System.Int32 ProcessorCount {get;}
StackTrace Property static System.String StackTrace {get;}
SystemDirectory Property static System.String SystemDirectory {get;}
TickCount Property static System.Int32 TickCount {get;}
UserDomainName Property static System.String UserDomainName {get;}
UserInteractive Property static System.Boolean UserInteractive {get;}
UserName Property static System.String UserName {get;}
Version Property static System.Version Version {get;}
WorkingSet Property static System.Int64 WorkingSet {get;}
Static Property values for [System.Environment]
CommandLine: : "C:\psp\PowerShellPlus.exe"
CurrentDirectory : C:\psp
ExitCode : 0
HasShutdownStarted : False
MchineName : COOKHAM8
NewLine :
OSVersion : Microsoft Windows NT 6.0.6001 Service Pack 1
ProcessorCount : 8
SystemDirctory : C:\Windows\system32
TickCount : -1879673533
UserDomainName : COOKHAM
UserInteractive : True
UserName : tfl
Version : 2.0.50727.1434
WorkingSet : 47669248
StackTrace:
at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at getter(Object )
at System.Management.Automation.DotNetAdapter.PropertyGet(PSProperty property)
at System.Management.Automation.Adapter.BasePropertyGet(PSProperty property)
at System.Management.Automation.PSProperty.GetAdaptedValue()
at System.Management.Automation.PSProperty.get_Value()
at System.Management.Automation.PropertyReferenceNode.GetValue(PSObject obj, Object property)
at System.Management.Automation.PropertyReferenceNode.Execute(Array input, Pipe outputPipe)
at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList)
at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultL
at System.Management.Automation.StatementListNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList)
at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe)
at System.Management.Automation.ScriptCommandProcessor.ExecuteWithCatch(ParseTreeNode ptn, Array inputToProcess)
at System.Management.Automation.ScriptCommandProcessor.RunClause(ParseTreeNode clause, Object dollarUnderbar, Object inputToProcess)
at System.Management.Automation.ScriptCommandProcessor.Complete()
at System.Management.Automation.CommandProcessorBase.DoComplete()
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumera
at System.Management.Automation.PipelineNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList)
at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultL
at System.Management.Automation.StatementListNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList)
at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe)
at System.Management.Automation.ScriptCommandProcessor.ExecuteWithCatch(ParseTreeNode ptn, Array inputToProcess)
at System.Management.Automation.ScriptCommandProcessor.RunClause(ParseTreeNode clause, Object dollarUnderbar, Object inputToProcess)
at System.Management.Automation.ScriptCommandProcessor.Complete()
at System.Management.Automation.CommandProcessorBase.DoComplete()
at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumera
at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
2 comments:
Hi Thomas, to have all properties in one one-liner, it's possible to use this code:
ForEach ($f in ([Environment] | Get-Member -MemberType Property -Static)) {
"{0} - {1}" -f $f.name, [Environment]::($f.name).ToString()}
Of course, it's not formatted in the way you did in your script. BTW: I like your 'quick' PS tips.
Regards,
David
Same formatting as in Thomas' script (with excluded StackTrace property):
foreach ($f in ([Environment] | Get-Member -MemberType Property -Static)) {if ($f.name -ne "StackTrace") {"{0,-19} : {1}" -f $f.name, [Environment]::($f.name).ToString()}}
Post a Comment