Tip: Cmdlets to Retrieve Basic System Information

Sometimes when you are working with a computer, you won’t know basic information, such as the name of the computer, the logon domain, or the current user. This can happen when you get called to support a computer in another department within your organization and when you are working remotely. Items that help you quickly gather basic user and system information include the following:
  • $env:computername Displays the name of the computer
    Usage: $env:computername
  • $env:username Displays the name of the user currently logged on to the system, such as wrstanek
    Usage: $env:username
  • $env:userdomain Displays the logon domain of the current user, such as CPANDL
    Usage: $env:userdomain
  • Get-Date Displays the current system date or current system time
    Usage: Get-Date [-Date] DateTime
  • Set-Date Sets the current system date or current system time
    Usage: Set-Date [-Date] DateTime
  • Get-Credential Gets a credential needed for authentication
    Usage: Get-Credential [-Credential] Credential


From the Microsoft Press book Windows PowerShell 2.0 Administrator’s Pocket Consultant by William R. Stanek.



Show: