Wednesday, June 8, 2016

Get System Environment value of remote computer - Powershell Script


<#
.SYNOPSIS
    This script demonstrates the use of System.Environment
.DESCRIPTION
    This script Uses a variety of the members of System.Environment and is
    a re-write of a MSDN Sample Script
.EXAMPLE
    PSH [C:\foo]: .\Get-System.Environment.ps1' foo1 foo2 foo3
    My system drive is C: and my system root is C:\Windows

.PARAMETER
    None, but if any are provided, they are displayed above
#>

##
# Start of Script
##

# Setup two variables for later use
[String] $str;
[string] $nl = [System.Environment]::NewLine

# Now display members of the environment class
"-- Environment members --"
#  Assume: You Invoke this sample with an arbitrary set of command line arguments.
"CommandLine       : {0}"   -f [system.environment]::CommandLine
$arguments = [System.Environment]::GetCommandLineArgs()
"GetCommandLineArgs: {0}"   -f [system.string]::join(", ", $arguments)
#  <-- Keep this information secure! -->
"CurrentDirectory  : {0}"   -f [System.Environment]::CurrentDirectory
"ExitCode          : {0}"   -f [System.Environment]::ExitCode
"HasShutdownStarted: {0}"   -f [System.Environment]::HasShutdownStarted
#  <-- Keep this information secure! -->
"MachineName       : {0}"   -f [System.Environment]::MachineName
"NewLine           : {0}  first line{0}  second line{0}  third line" -f [System.Environment]::NewLine
"OSVersion         : {0}"   -f [System.Environment]::OSVersion.ToString()
"StackTrace        : '{0}'" -f [System.Environment]::StackTrace
#  <-- Keep this information secure! -->
"SystemDirectory   : {0}"    -f [System.Environment]::SystemDirectory
"TickCount         : {0}"    -f [System.Environment]::TickCount
#  <-- Keep this information secure! -->
"UserDomainName    : {0}"    -f [System.Environment]::UserDomainName
"UserInteractive   : {0}"    -f [System.Environment]::UserInteractive
#  <-- Keep this information secure! -->
"UserName          : {0}"    -f [System.Environment]::UserName
"Version           : {0}"    -f [System.Environment]::Version.ToString()
"WorkingSet        : {0}"    -f [System.Environment]::WorkingSet
#  No example for exit(exitCode) because doing so would terminate this example.
#  <-- Keep this information secure! -->
$query = "My system drive is %SystemDrive% and my system root is %SystemRoot%";
$str = [System.Environment]::ExpandEnvironmentVariables($query)
"ExpandEnvironmentVariables: {0}  {1}" -f $nl,$str
"GetEnvironmentVariable: {0}  My temporary directory is {1}." -f $nl,[System.Environment]::GetEnvironmentVariable("TEMP")
""
"GetEnvironmentVariables: "
[System.Environment]::GetEnvironmentVariables()
"GetFolderPath: {0}" -f [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::System)
[String[]] $drives = [System.Environment]::GetLogicalDrives()
"GetLogicalDrives: {0}" -f [System.String]::Join(", ", $drives)
#End of Script

Reference - MSDN Gallery

No comments:

Post a Comment

Windows Server 2016 Key Features and License Prospects

If you are planning to move to Windows 2016 and looking for benefits, I have listed down below : Why Windows Server 2016? ·     ...