17 June 2011

Useful Command prompt (CMD) and PowerShell commands

This time I’ll make it short. In this blog I’ll start collecting useful Command prompt and PowerShell commands that I frequently use. Commands are inside the quotes:

Command prompt:

Did you ever search what is the username of the currently logged in user? Here is an answer:
Windows XP: “echo %username%
Windows 7: “whoami” or “echo %username%

And command that shows computer name:
Windows XP, 7, 2003, 2008: “hostname


************************************************
On the file server you need a list of all opened files:
net file
net file < .\desktop\openfiles.txt if the list is too long and doesn’t fit into command prompt window.
net file | find "Search string"
filter results by specified search string.


************************************************
Get a list of all drivers installed to Windows computer:
driverquery


************************************************Display user logon server (domain controller) in command line:
set
echo %logonserver%


************************************************
This tool displays operating system configuration information for a local or remote machine, including service pack levels, original install date, system boot time, total physical memory, available physical memory, page file max size, page file available, page file in use and much more:
"systeminfo"


************************************************
Get a list of all roles applied to Windows 2008 server:
servermanagercmd -q


************************************************
Detecting memory leaks:
Create memory snapshots into a file, if you run this command repeatedly new memory snapshots will be added to the end of the file:
"memsnap /m memsnap.log"
Analyze memory snapshots for memory leaks:
"memsnap /ah memsnap.log"


 
************************************************
This tool enables an administrator to display the MAC address for network adapters on a system:
"getmac /v"



************************************************
Group Policy Results (GPResult.exe) is a command line tool that displays Group Policy Settings that are in effect for a specific user or computer.
"gpresult /s ComputerName /user UserName /r /v > gpresult_filename.txt"


************************************************
Display / list Active directory FSMO (Flexible Single Master Operations) roles. Run this command on domain controller:
netdom query fsmo




************************************************
Get a list of group members from AD:
dsget group "CN=Domain Admins,CN=Users,DC=domain,DC=local" –members


************************************************
Get a list of disabled user accounts from AD:
DSQUERY USER -disabled


************************************************
Get a list of inactive user accounts from AD (in weeks):
DSQUERY USER -inactive 4


************************************************
Get a list of inactive computer accounts from AD (in weeks):
DSQUERY computer -inactive 4



************************************************
Get a list of all computer accounts and servers from AD (name and OS):
dsquery * -filter "(&(objectClass=Computer)(objectCategory=Computer))" -attr sAMAccountName operatingSystem -limit 1000


************************************************
Get AD schema version. Run this command on domain controller:
dsquery * cn=schema,cn=configuaration,dc=domain,dc=local -scope base -attr objectVersion


************************************************
Klist is a command line utility included in the default installation of Windows Server 2008 and Windows Server 2008 R2 which can be used to list and purge Kerberos tickets on a given computer. To run KLIST, open a command prompt in Windows Server 2008 and type Klist:
klist tickets


************************************************
Get Exchange schema version:
dsquery * CN=ms-Exch-Schema-Version-Pt,cn=schema,cn=configuration,dc=domain,dc=local -scope base -attr rangeUpper



************************************************
Get a list of Service Principal Name (SPN) for specified server:
setspn -l ServerName


************************************************
Get AD site information for computer on which you're running this command:
Nltest.exe /dsgetsite


************************************************
Get DFS server list for computer on which you're running this command:
dfsutil /pktinfo


This is it for today. Have fun!