Common Console Commands

Common Console Commands

Some Common Console Commands worth knowing

Here's some common/useful Console commands worth knowing that you may use while at a Command Prompt. These will work in DOS/CMD or PowerShell as they are external commands. You don't need to type them in using ALL CAPS, and you don't need to type .EXE - unless the name conflicts with a PowerShell alias
(eg. SC.EXE is an external command [Service Controller] but SC is a PowerShell alias for Set-Content [write text to a file]. Typing sc at a PowerShell prompt is the same as typing Set-Content, but typing sc.exe will run the Service Controller external command).

The commands are roughly grouped, and this will mainly be included/built-in Windows commands that would be useful for administering a Windows Server from the CLI. There's many more than just these of course - and Service specific ones are not listed (such as dfsradmin and dfsrdiag for DFS-R Service, or iisreset for IIS). Many of these you can run from a Windows Workstation, not just a Server.

Of course one major function is maintaining Active Directory, and while there are commands to manage AD using external CLI commands - they aren't pleasant or intuitive (eg. dsquery, dsadd, etc). A much more friendly, useful and powerful way to manage AD from the CLI is to use the PowerShell ActiveDirectory module. There's no way (or need!) to cover every AD related PowerShell command - you just need to learn how to discover PowerShell commands and some basic PowerShell knowledge in the PowerShell Boot Camp.

Some useful examples are given for each command, but the examples given are just that: an example and are by no means the only or even most useful way to use a command.
Most of these will display help if you add /? after, as in ping /? to find other options and uses.

Network Related Commands

Command Description
PING and
TRACERT
Send ICMP Echo packets to check if a host is up or not, eg: ping 8.8.8.8 useful options are -n to specify how many packets to send, and -t to ping for ever.
Such as: ping -n 10 www.google.ca, and tracert (Trace Route) does the same, but reports every hop along the way, using -d to not resolve hostnames.
IPCONFIG Display the TCP/IP setting to find the IP Address, DNS Server, etc. Use ipconfig /all to see all IP settings. You can also /release and /renew a DHCP IP.
Or try /displaydns or /flushdns to display or clear the DNS cache.
ROUTE You can print, add, change, or delete your IP route table, eg. route print
Or route add 172.16.40.0 mask 255.255.255.0 192.168.8.1 to route the 172.16.40.0/24 network via the 192.168.8.1 gateway.
NSLOOKUP DNS Name Server Lookup, you can also find Address (A), Mail (MX), Service (SRV), and Text (TXT) records, eg: nslookup -q=mx gmail.com to find Gmail's mail server.
You can find all Domain Controllers in Active Directory with nslookup -q=srv _ldap._tcp.some-domain.local or your WAN IP via OpenDNS using:
nslookup myip.opendns.com resolver1.opendns.com Or run just nslookup to use it interactively, type help at the > prompt for all the commands.
NETSH Manage and display all sorts of Network Interface / Wireless / Firewall / DNS / DHCP settings, for example to see details of the wifi networks around try:
netsh wlan show networks mode=bssid or just run netsh by itself for interactive mode and type help at the netsh> prompt.
NETSTAT Display TCP and UDP protocol stats, including what programs have what ports open for connections or IPs with established connections. Eg. netstat -ano
will display all Process IDs associated with IPs listening or having established TCP and UDP connections. Limit to just RDP with netstat -ano | findstr ":3389"

System Admin Commands

Command Description
DCDIAG and
REPADMIN
Run some Domain Controller (DC) diagnostic checks: try dcdiag /v /f:c:\output.txt to log verbose testing info to a file.
And check or force Replication between DCs eg: repadmin /syncall /A /P /d /e will force-push replication to all other DCs.
NET and
NETDOM
Manage local users, groups, machines, with NET, eg. to see all local Administrators: net localgroup Administrators
And change the local Administrator's password with: net use Administrator My$tr0ngPwd /yes
Or manage AD Domain computers, trusts, etc with NETDOM, eg: verify a PC's secure channel to a DC: netdom verify PC-NAME /d:some-domain.local
QWINSTA Shows how the long PowerShell names really are better: stands for Query WINdows STAtion - to find out who is logged on to a server, such as an RDS/TS.
You could then log someone off with LOGOFF id# where id# is the ID number returned from QWINSTA. You can also use QUERY SESSION.
GPUPDATE and
GPRESULT
Force updating GPOs on a workstation and logoff with: gpupdate /force /logoff
Or check GPO Resultant Set of Policies to see what GPOs are in effect with in an HTML report with: gpresult /H c:\output.htm
EVENTCREATE Add an entry to the Windows Event Log, can't create all Event IDs, only 1 - 1000. PowerShell has Get-EventLog and Get-WinEvent to view the logs.
For example, EVENTCREATE /ID 999 /L APPLICATION /T WARNING /SO ExampleApp /D "Example event triggered"
ICACLS Change, Display, Modify, Backup or Restore Access Control Lists (ACLs) of Files and Folders. Similar to Get-Acl and Set-Acl in PowerShell.
For example, replace all permissions with default inherited ACLs from the parent folder: ICACLS "c:\folder\*" /reset /T /C /L
TAKEOWN Take Ownership of a file or folders. Sometimes you need to do this before changing permissions if you've been denied access:
TAKEOWN /F "c:\folder\*" /R /D Y (can add /A to assign to the local Admin instead of the current user)
GIT The Git source code revision control system command (if installed). Full info on using Git here. Not included as part of Windows, but a common download for developers.
Two common commands are: git status to see the if there's files to commit in the current folder, and git log --oneline to see a brief summary of commits.
SQLCMD Execute a SQL Server script (.SQL file) against a SQL Instance, or run SQL commands. Also not a built-in command, but included with MS SQL server and commonly used by DBAs.
Mostly used interactively but you can run SQL queries from the command like: sqlcmd -E -S SERVER\Instance -Q "SELECT @@VERSION"

Computer Admin Commands

Command Description
WHOAMI and
SYSTEMINFO
See info about the currently logged in user, including group membership, with whoami /all /FO list
Or see a lot of info about PC/Server with: systeminfo, if you add /FO csv > c:\output.csv you can capture to a .CSV
WMIC WMI Controller, get or set all manner of WMI related objects. In PowerShell it's much better to use Get-WmiObject or Get-CIMInstance and related commands.
Also works interactively if no parameters provided: wmic, but try: wmic printer list brief /format:list to see all printers.
POWERCFG Retrive or Set various settings related to Power Usage on your system, such as Sleep, Hibernate, and other Power Scheme settings. See a report of the battery
health, capacity, and usage for the last 14 days: powercfg /batteryreport /duration 14 /output c:\temp\bettery.html
TASKLIST Display all the running processes (like Task Manager), you can filter (tasklist /? to see all the various ways) such as: tasklist /fi "imagename eq notepad*"
TASKKILL Kill or End a particular task/process, it supports many of the same filtering options as TASKLIST but usually by Process ID (PID), eg: taskkill /pid 123456 /f
SC.EXE View (query), start, stop Windows Services - in PowerShell you need to include .exe or it will be an alias of Set-Content. In PowerShell you could also use Get-Service
Start the print spooler service: sc.exe start spooler or set it to manual start: sc.exe config spooler start= demand (use start= auto for Automatic start)
WHERE.EXE Find a command or partial command by searching the PATH environment variable, eg. where.exe psexec.exe or where.exe *bde*.exe
In PowerShell you need to include .EXE or it will assume you mean Where-Object, but just use Get-Command instead.
DIR ENV: or
SET and PATH
Show all environment variables, the first works only in PowerShell, the other two only in CMD Command Prompt (PATH just shows the PATH variable)
You can set/change environment variables but they will only persist in and as long as your Console window remains open - permanent changes must be made via the registry.
START and
RUNAS
Start a new process, you can also start a file to open in the associated program, eg to open a Word file use: start "" "some file.docx" Or just start .
to open Windows File Explorer in the current directory. runas /user:otheruser example.exe lets you start a process as another user (it will prompt for a password).
NOTEPAD Obviously not a command line tool, but if you are editing scripts then notepad scriptFile.ps1 is important.
Better editors will have more options and switches, but even Notepad offers /A and /W before the filename to open in ANSI or UNICODE mode.
MSIEXEC The MSI Installer Tool used to install or uninstall .MSI based programs, a common usage is to silently install an application and log the results, eg:
msiexec /i someProgram.msi /qn /norestart /log c:\logFile.txt then you can check c:\logFile.txt for success/failure.
REG View (query), Change (add), delete, import, export Registry Values or whole Keys. For example, to allow multiple RDP sessions on a Windows Server:
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fSingleSessionPerUser /d 0 /t REG_DWORD /f
SCHTASKS View (query), Change, delete, create, or control Scheduled Tasks. Eg. to set a task to run as SYSTEM instead of a user:
SCHTASKS /change /RU "NT AUTHORITY\SYSTEM" /tn "Name of Task"
SHUTDOWN and
LOGOFF
Shutdown or Restart a computer (local or remote), eg to reboot in 30 seconds: shutdown /r /t 30 you can add /m \\computerName for a remote PC,
or use /s for /r to shutdown. Use shutdown /a to abort within the timeout period. If you just want to logoff try: logoff, which can also logoff other sessions.
FC File Compare to see if two files are identical. With text files it also shows you the different lines (it compares line by line), Eg: fc file1.txt c:\temp\file2.txt
ATTRIB View, Set or Clear file attributes, including Read Only, Hidden and System. attrib by itself shows them, while attrib +H file.txt will hide a file.
XCOPY and
ROBOCOPY
Advanced Copy commands that can copy whole file/folder trees, eg: xcopy c:\source\*.* c:\dest /C /H /E /K /R /Y
Robust Copy has many options and is very powerful for copying whole file structures with permissions, throttling, exclusions, retries, timeouts, etc like:
robocopy c:\source \\server\destShare\ /log:c:\log.txt /MT:16 /e /copyall /dcopy:DAT /secfix /timfix /zb /R:2 /W:5
CHKDSK Run or schedule a Check Disk on a volume to look for disk errors, if the drive is in use it can be scheduled for next reboot: chkdsk c: /f /r
MANAGE-BDE Manage BitLocker state on the computer, including Encrypting and Decrypting a drive. Check the status of BitLocker with: manage-bde.exe -status c:
FINDSTR or
FIND
When the output of a command is too long you can | (pipe) it to findstr or find to filter based on some text string. Don't use find in PowerShell,
in fact in PowerShell you probably want to use Where anyway. But findstr works in both, eg: dir \ | findstr /I "Windows"
SORT and
MORE
Other commands you can | (pipe) output to. To sort the output or page it one screen at a time - press the Space bar for the next page, eg: dir \windows | more
and then press Space or q to quit.

This is by no means a complete list of all (or even useful) built-in Windows commands, there are more included Windows console .EXE applications, and as noted: some that are only installed if certain roles are installed. And there are a lot more 3rd party console/CLI/shell programs that can be downloaded (such as the PsTools from SysInternals).

What about the PowerShell versions of these commands (and more)? There are simply too many to list! My system has over 3,000 PowerShell commands/cmdlets, so there would be little point in listing them all. Plus, since PowerShell is so much more regular and discoverable it is actually more instructive to learn how to find the PowerShell command you want rather than be given a huge list. See the PowerShell Boot Camp for how to discover, and work with, PowerShell commands.