01- Fifty Basic Windows Commands With Examples
01- Fifty Basic Windows Commands With Examples
Learn basic windows commands that can help you with troubleshooting,
configuration, and gathering system details.
Most of these commands are built into windows so there is no need to download or
install anything (the only exception is the Sysinternals commands). Also, these
Windows Commands can be run from the command prompt or PowerShell console.
Tip: Most windows commands include a help menu that lists all the command
options and syntax. Type the command followed by /? to view the help menu.
For example, ping /?
The ping command is still one of my favorite tools for testing basic network
connectivity. It’s fast and very easy to use. In addition, I use it for the following:
Ping Examples
ping 192.168.100.1
Ping by hostname.
ping dc1.ad.activedirectorypro.com
For most windows commands you can type the command followed by /? to view the
help info, it will display the full syntax and parameters. So to view the help for ping
use this command:
ping /?
-l switch specifies a packet size.
ping -a 142.250.177.46
-t switch will do a continuous ping. A very popular command for testing network
connectivity.
ping -a 192.168.5.1
For more details on the ping command see Microsoft’s ping documentation.
This command can also display the DNS cache on the local machine, flush DNS,
release and renew the DHCP address on all network cards.
To view the IP configuration for all network cards on a computer type the command
below and press enter.
ipconfig /all
ipconfig /all
ipconfig /flushdns
/registerdns to trigger dynamic registration of the DNS names and IP addresses that
are configured on the computer.
ipconfig /registerdns
/release to release DHCP addresses. This will release DCHP address on the network
cards that are configured for DHCP.
ipconfig /release
/renew switch will renew DHCP address for all network cards.
ipconfig /renew
ipconfig /displaydns
The nslookup command is used to check DNS records and troubleshoot DNS. This is
a must-have command for any sysadmin or network engineer. You can do all kinds of
tests to verify DNS is working correctly, you can check PTR, A, MX, SOA, and many
other types of DNS records. It’s another one of my favorite windows commands for
network troubleshooting.
This command I don’t use very often but still comes in handy when troubleshooting
the network. For example, we had some speed issues with a website from our ISP, on
a different ISP we had no issues. The ISP had us run a traceroute so they could see
the path it took.
Tracert examples
The syntax for this command is tracert followed by the hostname or IP.
tracert google.com
This command has very few options. The only command line switch on this one that I
find useful is the -d which is used to not resolve the address to hostname.
5. shutdown command
The shutdown command does exactly that, it shuts down a computer. This command
is useful for shutting down or restarting local or remote computers. It also provides a
quick way to see all the logs for why a computer restarted or was shut down.
shutdown examples
This command will restart computer pc2.
shutdown /r /m \\pc2
shutdown /s /m \\pc2
shutdown /d
Here is an example output for the shutdown /d command. This can be useful to
quickly check why a computer restarted or shutdown.
More shutdown examples
Some of these use multiple switches, refer to the help file shutdown /? for an
explanation of each command switch.
shutdown /l /m \\pc2
shutdown /r /m \\pc2 /t 0
Shutdown the local computer and specify the time period before shutdown in
seconds.
shutdown /s /t 60
shutdown /a
shutdown /s /f
This command will pull down any GPO changes to the computer.
gpupdate
Use /force to reapply all the GPOs on the computer.
gpupdate /force
Check out my gpupdate tutorial for more examples and a video walkthrough.
The netstat command displays TCP/IP connection information, ethernet stats, and the
computer’s routing table. As a sysadmin I use this command on Windows servers and
clients when troubleshooting connection issues. I can verify application servers are
working correctly by checking that the service is running and listening for
connections on the port.
netstat -a
netstat -a -n
Here is the output of the above command. You can see how you can verify server and
client connectivity. It shows that my domain controller with IP 192.168.100.10 has
established these four connections with IP 192.168.100.11.
More netstat examples
netstat -ab
Displays ethernet statistics. This is a quick way to check for network card errors and
discards.
netstat -e
Displays the exe and the process ID (PID) associated with the connection.
netstat -abo
netstat -r
netstat -af
dcdiag examples
Examples
In this example, I will stop and start the printer spooler service.
10. systeminfo
The systeminfo command displays configuration details on a computer such as OS
name and version, hardware information, boot time, logon server, and more.
There are a lot of details this command displays, I like to use this command to check
the windows server uptime and when it was last booted.
You can run this command on remote computers with the /s parameter.
This command returns the MAC address from all the network cards on a system.
When troubleshooting a client connection issue I will often need the computer’s MAC
address so I can verify I see it connected on the switch. This command is the best way
to quickly grab a computer’s MAC address.
getmac /s pc1
This is another must know command if you work with Active Directory servers.
To display all applied GPOs run this command. Note: You need to run the command
prompt in administrator mode or it will not generate a full report.
gpresult /r
The above command will give a report for both user and computer applied GPOs.
and the computer settings.
More GPResult examples
gpresult /r /scope:user
gpresult /r /scope:computer
gpresult /s pcname
gpresult /h c:\report.html
whoami
whoami /groups
Pretty cool right?
whoami /upn
whoami /user
whoami /all
If you know the port number the application runs on you can use the command
below. In this example, I installed filezilla server so port 21 should be open.
telnet srv01 21
You may or may not get a response back from the remote server. In this case with
filezilla I do. You could also just get a blank screen on a successful connection.
If it doesn’t get a connection you should get a message like the below.
That is all I use the telnet client for. For complete command syntax view Microsoft’s
telnet documentation.
I don’t use this command that often but still is useful to check a user’s logon server or
quickly look at the environment variables.
One little trick with this command is you can type the command followed by string
and it will only display those results. For example, if I want to find everything that
starts with path I would use this command
set path
cd windows
You can also start typing the directory name and hit tab to auto complete. For example, to change to the “Program
Files” directory I can type cd pro and hit tab and it will auto complete the path.
sfc /scannow
You can also run a test only without repairing it.
sfc /verifyonly
chkdsk
Use /F to fix any errors found on the disk.
chkdsk /f
route print
22. powercfg (Power Settings)
List and configure power settings with the powercfg command
powercfg /list
Check out the powercfg guide from Windows Central for more examples.
25. format
The format command is used to format a partition on a hard drive or flash drive. This
will wipe all data from the partition.
In this example, I will format the E drive to the NTFS file system.
format e: /fs:NTFS
At the windows command prompt type cls and press enter to clear the screen.
27. diskpart
Diskpart allows you to manage disks, partitions, and volumes on your local computer.
You can delete, create, format, extend and shrink volumes.
diskpart
list disk
28. robocopy
Robocopy allows you to easily copy files and directories from one location to another.
This is a very popular windows command for moving file servers to another server.
For more examples, check out my guide 21 robocopy examples with screenshots.
29. xcopy
Xcopy is another windows command used to copy files and folders. To copy all files
and folders to a new location use this command.
30. del
The del command is used to delete files and folders. Deleting files with the del
command does not go to the recycle bin.
del c:\it\pass.txt
del c:\it\*.exe
assoc
Here is an example of creating a file association. I will associate the .jpg file extension
with jpegfile file type.
assoc .jpg=jpgfile
schtasks
34. arp
The arp command displays and modifies the Address Resolution Protocol (ARP) cache
on the local computer.
Display the arp cache for all interfaces:
arp -a
arp -d
35. hostname
This windows command displays the host name of the computer.
hostname
36. cipher (encrypt data)
The cipher command is useful for overwriting deleted data in windows. When you
delete data from Windows the data can be recovered by using data recovery
software. With the cipher command, you can remove the deleted data from the disk
so no one can recover it.
To overwrite deleted data on a volume use the /w switch. For example, I’ll clean the
c:\it\private path
cipher /w:c:\it\private
In this example, I’ll check the difference between two text files (ping1.txt and
ping2.txt).
fc c:\it\ping1.txt c:\it\ping2.txt
38. psexec
PsExec allows you to execute commands on remote computers. This is useful when
you need to troubleshoot a remote computer without taking full control of it.
In this example, I’ll run ipconfig on the remote computer pc1 to get the IP address
information.
39. Sysinternals
Sysinternals is a suite of utilities developed by Mark Russinovich and Bryce Cogswell
that is used to troubleshoot and monitor Windows computers. The suite of tools
became very popular with IT administrators for monitoring windows processes and
gathering system details. In 2006 Microsoft acquired the company and its assets.
You can download the suite of tools from the Sysinternals website.
rsop
41. mmc
mmc opens the Microsoft Management Console. You can then add/remove your own
snap-ins for quick access to different management consoles.
42. dir
The dir command lists all files and directories in a specific directory.
dir
To list the contents of another folder either change to that directory or type dir and
its path. For example, I’ll list the contents of c:\it\private.
dir c:\it\private
If the directory has a lot of files and folders you may want to pause the directory
listing so you can view it.
dir /p
43. runas
Runas allows you to run a specific tool or program as a different user. For example,
you are logged in as a regular user (no administrator rights) and you need to run a
program with an account that has local administrator rights.
In this example, I’m logged in as adpro\adam.reed and I’ll run a program (notepad) as
the local administrator account.
runas /user:administrator c:\windows\notepad.exe
The default command will only delete empty directories. If you want to delete a
directory and the files in the directory use the /s switch.
For example, I’ll delete the c:\it\private and all files in that directory.
rmdir c:\it\private /s
Install a package.
msiexec /i c:\install_file.msi
47. ver
The ver command displays the Windows version.
48. manage-bde (BitLocker)
Check bitlocker status, encrypt and decrypt data drives.
manage-bde -status
manage-bde -on
49. findstr
Findstr searches for patterns of text in files.
For example, I’ll look for the word food in file ping1.txt
The above command will search inside the file for any instance of the string food.
50. mstsc
The mstsc command starts a remote desktop session to another computer or allows
you t edit a .rdp configuration file.
Connect to the server using full screen, I’ll use 192.168.100.10 in these examples.
mstsc /f 192.168.100.10
Span rdp across multiple monitors.
You can type help to get a list of the system default commands.
Unfortunately, this will not list commands that have been installed by other programs
like the RSAT tools. To see a complete list of commands the Microsoft Windows
Commands documentation.
This is a great question as some commands will not run unless the command prompt
is in administrator mode.