Showing posts with label system.environment. Show all posts
Showing posts with label system.environment. Show all posts

Monday, 3 August 2009

Get-System.Environment.ps1

  1. <#
  2. .SYNOPSIS
  3. This script demonstrates the use of System.Environment
  4. .DESCRIPTION
  5. This script Uses a variety of the members of System.Environment and is
  6. a re-write of a MSDN Sample Script
  7. .NOTES
  8. File Name : Get-System.Environment
  9. Author : Thomas Lee - tfl@psp.co.uk
  10. Requires : PowerShell V2 CTP3
  11. .LINK
  12. This script posted to:
  13. http://www.pshscripts.blogspot.com
  14. MSDN Sample posted at:
  15. http://msdn.microsoft.com/en-us/library/system.environment.aspx
  16. .EXAMPLE
  17. PSH [C:\foo]: .\Get-System.Environment.ps1' foo1 foo2 foo3
  18. My system drive is C: and my system root is C:\Windows
  19. -- Environment members --
  20. CommandLine : "C:\Users\tfl\Desktop\psp\PowerShellPlus.exe"
  21. GetCommandLineArgs: C:\Users\tfl\Desktop\psp\PowerShellPlus.exe
  22. CurrentDirectory : C:\Users\tfl\Desktop\psp
  23. ExitCode : 0
  24. HasShutdownStarted: False
  25. MachineName : COOKHAM8
  26. NewLine :
  27. first line
  28. second line
  29. third line
  30. OSVersion : Microsoft Windows NT 6.0.6001 Service Pack 1
  31. StackTrace : ' at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
  32. at System.Environment.get_StackTrace()
  33. at getter(Object )
  34. at System.Management.Automation.DotNetAdapter.PropertyGet(PSProperty property)
  35. at System.Management.Automation.Adapter.BasePropertyGet(PSProperty property)
  36. at System.Management.Automation.PSProperty.GetAdaptedValue()
  37. at System.Management.Automation.PSProperty.get_Value()
  38. at System.Management.Automation.PropertyReferenceNode.GetValue(PSObject obj, Object property, ExecutionContext context)
  39. at System.Management.Automation.PropertyReferenceNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
  40. at System.Management.Automation.ExpressionNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
  41. at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  42. at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  43. at System.Management.Automation.StatementListNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  44. at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
  45. at System.Management.Automation.ScriptCommandProcessor.ExecuteWithCatch(ParseTreeNode ptn, Array inputToProcess)
  46. at System.Management.Automation.ScriptCommandProcessor.RunClause(ParseTreeNode clause, Object dollarUnderbar, Object inputToProcess)
  47. at System.Management.Automation.ScriptCommandProcessor.Complete()
  48. at System.Management.Automation.CommandProcessorBase.DoComplete()
  49. at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)
  50. at System.Management.Automation.PipelineNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  51. at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  52. at System.Management.Automation.StatementListNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
  53. at System.Management.Automation.ParseTreeNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
  54. at System.Management.Automation.ScriptCommandProcessor.ExecuteWithCatch(ParseTreeNode ptn, Array inputToProcess)
  55. at System.Management.Automation.ScriptCommandProcessor.RunClause(ParseTreeNode clause, Object dollarUnderbar, Object inputToProcess)
  56. at System.Management.Automation.ScriptCommandProcessor.Complete()
  57. at System.Management.Automation.CommandProcessorBase.DoComplete()
  58. at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input, Hashtable errorResults, Boolean enumerate)
  59. at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecute(Array input, Hashtable errorResults)
  60. at System.Management.Automation.Runspaces.LocalPipeline.InvokeHelper()
  61. at System.Management.Automation.Runspaces.LocalPipeline.InvokeThreadProc()
  62. at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  63. at System.Threading.ExecutionContext.runTryCode(Object userData)
  64. at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
  65. at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
  66. at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  67. at System.Threading.ThreadHelper.ThreadStart()'
  68. SystemDirectory : C:\Windows\system32
  69. TickCount : 98385431
  70. UserDomainName : COOKHAM
  71. UserInteractive : True
  72. UserName : tfl
  73. Version : 2.0.50727.3074
  74. WorkingSet : 49385472
  75. ExpandEnvironmentVariables:
  76. My system drive is C: and my system root is C:\Windows
  77. GetEnvironmentVariable:
  78. My temporary directory is C:\Users\tfl\AppData\Local\Temp.
  79. GetEnvironmentVariables:
  80. Name Value
  81. ---- -----
  82. Path C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\b...
  83. TEMP C:\Users\tfl\AppData\Local\Temp
  84. SESSIONNAME Console
  85. PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PSC1
  86. USERDOMAIN COOKHAM
  87. PROCESSOR_ARCHITECTURE x86
  88. ProgramW6432 C:\Program Files
  89. APPDATA C:\Users\tfl\AppData\Roaming
  90. windir C:\Windows
  91. LOCALAPPDATA C:\Users\tfl\AppData\Local
  92. CommonProgramW6432 C:\Program Files\Common Files
  93. TMP C:\Users\tfl\AppData\Local\Temp
  94. USERDNSDOMAIN COOKHAM.NET
  95. USERPROFILE C:\Users\tfl
  96. ProgramFiles C:\Program Files (x86)
  97. CommonProgramFiles(x86) C:\Program Files (x86)\Common Files
  98. FP_NO_HOST_CHECK NO
  99. HOMEPATH \Users\tfl
  100. COMPUTERNAME COOKHAM8
  101. CLASSPATH .;C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
  102. PROCESSOR_ARCHITEW6432 AMD64
  103. ProgramData C:\ProgramData
  104. NUMBER_OF_PROCESSORS 8
  105. PROCESSOR_IDENTIFIER Intel64 Family 6 Model 23 Stepping 6, GenuineIntel
  106. SystemDrive C:
  107. SystemRoot C:\Windows
  108. ComSpec C:\Windows\system32\cmd.exe
  109. LOGONSERVER \\COOKHAM1
  110. ProgramFiles(x86) C:\Program Files (x86)
  111. PSMODULEPATH C:\Users\tfl\Documents\WindowsPowerShell\Modules;C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules
  112. CommonProgramFiles C:\Program Files (x86)\Common Files
  113. PROCESSOR_LEVEL 6
  114. PROCESSOR_REVISION 1706
  115. QTJAVA C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
  116. ALLUSERSPROFILE C:\ProgramData
  117. VS90COMNTOOLS C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\
  118. PUBLIC C:\Users\Public
  119. USERNAME tfl
  120. OS Windows_NT
  121. HOMEDRIVE C:
  122. GetFolderPath: C:\Windows\system32
  123. GetLogicalDrives: C:\, D:\, E:\, F:\, G:\, H:\, I:\, J:\, K:\, L:\, Q:\, X:\
  124. .PARAMETER
  125. None, but if any are provided, they are displayed above
  126. #>
  127. ##
  128. # Start of Script
  129. ##
  130. # Setup two variables for later use
  131. [String] $str;
  132. [string] $nl = [System.Environment]::NewLine
  133. # Now display members of the environment class
  134. "-- Environment members --"
  135. # Assume: You Invoke this sample with an arbitrary set of command line arguments.
  136. "CommandLine : {0}" -f [system.environment]::CommandLine
  137. $arguments = [System.Environment]::GetCommandLineArgs()
  138. "GetCommandLineArgs: {0}" -f [system.string]::join(", ", $arguments)
  139. # <-- Keep this information secure! -->
  140. "CurrentDirectory : {0}" -f [System.Environment]::CurrentDirectory
  141. "ExitCode : {0}" -f [System.Environment]::ExitCode
  142. "HasShutdownStarted: {0}" -f [System.Environment]::HasShutdownStarted
  143. # <-- Keep this information secure! -->
  144. "MachineName : {0}" -f [System.Environment]::MachineName
  145. "NewLine : {0} first line{0} second line{0} third line" -f [System.Environment]::NewLine
  146. "OSVersion : {0}" -f [System.Environment]::OSVersion.ToString()
  147. "StackTrace : '{0}'" -f [System.Environment]::StackTrace
  148. # <-- Keep this information secure! -->
  149. "SystemDirectory : {0}" -f [System.Environment]::SystemDirectory
  150. "TickCount : {0}" -f [System.Environment]::TickCount
  151. # <-- Keep this information secure! -->
  152. "UserDomainName : {0}" -f [System.Environment]::UserDomainName
  153. "UserInteractive : {0}" -f [System.Environment]::UserInteractive
  154. # <-- Keep this information secure! -->
  155. "UserName : {0}" -f [System.Environment]::UserName
  156. "Version : {0}" -f [System.Environment]::Version.ToString()
  157. "WorkingSet : {0}" -f [System.Environment]::WorkingSet
  158. # No example for exit(exitCode) because doing so would terminate this example.
  159. # <-- Keep this information secure! -->
  160. $query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
  161. $str = [System.Environment]::ExpandEnvironmentVariables($query)
  162. "ExpandEnvironmentVariables: {0} {1}" -f $nl,$str
  163. "GetEnvironmentVariable: {0} My temporary directory is {1}." -f $nl,[System.Environment]::GetEnvironmentVariable("TEMP")
  164. ""
  165. "GetEnvironmentVariables: "
  166. [System.Environment]::GetEnvironmentVariables()
  167. "GetFolderPath: {0}" -f [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)
  168. [String[]] $drives = [System.Environment]::GetLogicalDrives()
  169. "GetLogicalDrives: {0}" -f [System.String]::Join(", ", $drives)
  170. #End of Script

Monday, 5 January 2009

Get-System.EnvironmentsStaticProperties1.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Demonstrates the static properties on System.Environment 
  4. .DESCRIPTION 
  5.     This script uses the System.Environment class to retrieve interesting 
  6.     information about your system. The fields returned are static fields  
  7.     on the System.Environment class. 
  8. .NOTES 
  9.     File Name  : Get-System.EnvironmentStaticProperties1.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 CTP3 
  12. .LINK 
  13.     http://www.pshscripts.blogspot.com 
  14. .EXAMPLE 
  15.     PS c:\Foo> .\Get-System.EnvironmentStaticProperties1.ps1 
  16.     Static properties in [System.Environment] 
  17.        TypeName: System.Environment 
  18.  
  19.     Name               MemberType Definition 
  20.     ----               ---------- ---------- 
  21.     CommandLine        Property   static System.String CommandLine {get;} 
  22.     CurrentDirectory   Property   static System.String CurrentDirectory {get;set;} 
  23.     ExitCode           Property   static System.Int32 ExitCode {get;set;} 
  24.     HasShutdownStarted Property   static System.Boolean HasShutdownStarted {get;} 
  25.     MachineName        Property   static System.String MachineName {get;} 
  26.     NewLine            Property   static System.String NewLine {get;} 
  27.     OSVersion          Property   static System.OperatingSystem OSVersion {get;} 
  28.     ProcessorCount     Property   static System.Int32 ProcessorCount {get;} 
  29.     StackTrace         Property   static System.String StackTrace {get;} 
  30.     SystemDirectory    Property   static System.String SystemDirectory {get;} 
  31.     TickCount          Property   static System.Int32 TickCount {get;} 
  32.     UserDomainName     Property   static System.String UserDomainName {get;} 
  33.     UserInteractive    Property   static System.Boolean UserInteractive {get;} 
  34.     UserName           Property   static System.String UserName {get;} 
  35.     Version            Property   static System.Version Version {get;} 
  36.     WorkingSet         Property   static System.Int64 WorkingSet {get;} 
  37.      
  38.     Static Property values for [System.Environment] 
  39.     CommandLine:       : "C:\Users\tfl\Desktop\psp\PowerShellPlus.exe" 
  40.     CurrentDirectory   : C:\Users\tfl\Desktop\psp 
  41.     ExitCode           : 0 
  42.     HasShutdownStarted : False 
  43.     MchineName         : 
  44.     NewLine            : 
  45.  
  46.  
  47.     OSVersion          : Microsoft Windows NT 6.0.6001 Service Pack 1 
  48.     ProcessorCount     : 8 
  49.     SystemDirctory     : C:\Windows\system32 
  50.     TickCount          : 261135752 
  51.     UserDomainName     : COOKHAM 
  52.     UserInteractive    : True 
  53.     UserName           : tfl 
  54.     Version            : 2.0.50727.1434 
  55.  
  56.     Stack Trace 
  57.             { Snipped - Left as an exercise for the reader...} 
  58. #> 
  59.  
  60. ### 
  61. #  Start Script 
  62. ## 
  63.  
  64. # Get and display statics in system.environment class 
  65. "Static properties in [System.Environment]" 
  66. [System.Environment] | Get-Member -Static -MemberType properties 
  67.  
  68. # Now display the values of the simple static properties 
  69. "";"Static Property values for [System.Environment]" 
  70. "CommandLine:       : {0}" -f [System.Environment]::CommandLine 
  71. "CurrentDirectory   : {0}" -f [System.Environment]::CurrentDirectory 
  72. "ExitCode           : {0}" -f [System.Environment]::ExitCOde 
  73. "HasShutdownStarted : {0}" -f [System.Environment]::HasShutdownStarted 
  74. "MchineName         : {0}" -f [System.Environment]::MachineNam 
  75. "NewLine            : {0}" -f [System.Environment]::NewLine 
  76. "OSVersion          : {0}" -f [System.Environment]::OSVersion 
  77. "ProcessorCount     : {0}" -f [System.Environment]::ProcessorCount 
  78. "SystemDirctory     : {0}" -f [System.Environment]::SystemDirectory 
  79. "TickCount          : {0}" -f [System.Environment]::TickCount 
  80. "UserDomainName     : {0}" -f [System.Environment]::UserDomainName 
  81. "UserInteractive    : {0}" -f [System.Environment]::UserInteractive 
  82. "UserName           : {0}" -f [System.Environment]::UserName 
  83. "Version            : {0}" -f [System.Environment]::Version 
  84. "WorkingSet         : {0}" -f [System.Environment]::WorkingSet   
  85.  
  86. # Here is the stack trace: 
  87. "";"Stack Trace:" 
  88. [System.Environment]::StackTrace 
  89. # End of Script 

Tuesday, 16 December 2008

Get-System.EnvorinmentStaticProperties1.ps1

# 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()