Everything old is new again. Windows users of a certain age remember the MS-DOS command line, perhaps not so fondly. But even after 20 years of trying to ditch its command-line past, Windows 10 still rewards those who understand the benefits of using a command line for some common tasks.

As system administrators have known all along, sometimes typing a command is just faster than using a graphical interface, and that’s even truer for scripts that can carry out entire sequences of commands. Windows 10 includes a new-age command-based environment called Windows PowerShell, which offers tremendous power to those who are willing to invest a little time learning its ways.

But let’s begin with…

The good ol’ Command Prompt

The Windows Command Processor, Cmd.exe, is only superficially similar to its ancient forebear, MS-DOS. On a 64-bit Windows 10 system, Cmd.exe is a 64-bit native Windows process. The easiest way to open a Command Prompt is via the Quick Links menu (right-click Start or use the keyboard shortcut Windows key+X). That menu includes two Command Prompt options: one that runs under your user account and the other that runs as an Administrator.

You can also type Cmd in the search box and then click Command Prompt in the results list, or right- click that entry and then, on the shortcut menu, choose Open As Administrator to open an elevated Command Prompt window. The only visible difference between the two ways of starting this environment is the Administrator prefix, which appears in the title bar in an elevated Command Prompt session. You can see that subtle change in screenshot below, where I’ve also opened the customization properties for the Command Prompt window by right-clicking the icon at the left of the title bar and then choosing Properties.

screen-shot-2016-10-20-at-1-25-04-am

Go from File Explorer to a Command Prompt with two clicks

You’re in File Explorer. You want to open a Command Prompt window in the current folder. Fortunately, there’s a shortcut for that: Hold down the Shift key as you right-click any empty space in the folder (make sure no files are selected) and then, on the shortcut menu, click Open Command Window Here.

 

If you’re not sure what you can do in a Windows 10 Command Prompt window, try typing help. That returns a list of 84 commands, with a brief description for each one. Want full syntax for a command? In the Command Prompt window, type the command name followed by the /? switch.

The command line is useful for some file management tasks, with syntax that hasn’t changed much since the days of MS-DOS. Thanks to wildcard characters, you can change the extension on a group of files in a folder, for example, using the command ren *.htm *.html. That job is nearly impossible in File Explorer.

But there are also a handful of commands you probably don’t know that can come in extremely handy. The following list contains a few commands I use regularly:

  • Systeminfo This handy command spits out a lengthy description of the current system, including the host name, the Windows version and original installation date, domain or workgroup membership, networking details, and much more. Screenshot below shows a small portion of the output you can expect. Follow the command with the > symbol, followed by the full path of a destination file, to save the results in a file that you can consult later.screen-shot-2016-10-20-at-1-31-01-am
  • Driverquery If you’re curious about which drivers are installed on a given system (local or remote), this command is your friend. Use the /FO CSV switch to specify that you want the output in comma-separated values (CSV) format; redirect that output to a file and you can open it in Excel for more detailed analysis.
  • Icacls This oddly named command allows you to manipulate permissions (access control lists, or ACLs) on files and folders. If you’re unable to delete or rename a file or folder because of permissions, this command can help.
  • Shutdown Sometimes, the Power menu doesn’t contain the options you really need. This command, with its many switches (/r for restart and /s for shutdown, to name just two), can cover those different scenarios. Using the /t switch, you can specify how long to wait (in seconds) before executing the command. (The default is 30 seconds.) If you have a few tasks to finish up before lunch and want your PC to restart in 15 minutes, use the command shutdown /r /t 900. That produces a notification like the one shown in the image that follows. If you change your mind, use shutdown /a to cancel the planned shutdown or restart.screen-shot-2016-10-20-at-1-36-51-am
  • Sc With this, you can query, start, pause, stop, and configure services using the Service Control Manager. Its syntax is daunting but its capabilities are extremely powerful.
  • Tasklist and Taskkill Using these matching commands, you can generate a list of running tasks and then forcibly end any process on that list. Taskkill is a blunt weapon but effective when you need it.

For faster navigation in a Command Prompt window, it’s worth noting how the arrow keys work. Use the up and down arrows to scroll through and recall recent commands. Use the right arrow to repeat the previous command one character at a time, which can save you some typing if you need to reissue a command with a different parameter or switch. Finally, after recalling or entering a command but before pressing Enter, use the left and right arrows to move through the command and make changes as needed. When editing a command, press the Insert key to toggle between overtype mode (in which whatever you type replaces the existing contents of the command line) and insert mode, which adds whatever you type without disturbing the current command.

Introducing Windows PowerShell

The Windows 10 Command Prompt can trace its ancestry back more than three decades. Windows PowerShell is distinctly more modern, with version 1.0 arriving on the scene a mere decade ago.

PowerShell is an incredibly rich environment built for system administrators to automate tasks and configurations. Instead of a limited number of commands, Windows PowerShell offers cmdlets, which work with the file system, the registry, certificate stores, and just about anything in Windows (desktop and server editions) that you can manage. Cmdlets are available in core modules that are included with every edition of Windows 10. And, of course, the real goal for many of these cmdlets is for you to be able to combine them into scripts. If you’re an administrator, you can use these scripts to perform repetitive management tasks quickly and effectively.

If you’re not a system administrator, the sheer scope of Windows PowerShell can be extremely intimidating. But some tasks, including managing Microsoft Azure and Office 365, are ideally suited for Windows PowerShell commands. In this section, I just want to introduce the basics of Windows PowerShell so that you feel comfortable when you’re required to dive into the deep end.

Windows PowerShell includes its own command-line environment, with a distinctive blue background that sets it apart from the Windows 10 Command Prompt. As screenshot below illustrates, one of the first things any Windows PowerShell neophyte should do is to issue the Get-Help cmdlet, which includes a link to online help and detailed instructions for using the Update-Help cmdlet.
screen-shot-2016-10-20-at-1-43-39-am

Add a word to the end of Get-Help and you can find cmdlets that include that term. If you know there’s a cmdlet for managing BitLocker but you can’t remember exactly which one you need, try Get-Help Bitlocker to display this list. And you can jump directly to the online reference for a specific cmdlet by using the syntax Get-Help -Online.

screen-shot-2016-10-20-at-1-45-03-am
Although Windows PowerShell cmdlets follow consistent capitalization, you don’t need to worry about case. And if you’re not sure of the exact name of a cmdlet, you can press the Tab key and use IntelliSense to offer suggestions. For example, type get-p and then press Tab to see the first matching cmdlet, Get-Package. Keep pressing Tab to cycle through Get-PackageProvider, Get-PackageSource, Get-Partition, and so on.
If you need more help, consider using the Windows PowerShell Integrated Scripting Environment (ISE), which offers a point-and-click graphical interface that takes a lot of the guesswork out of typing cmdlets. As screenshot shows the Windows PowerShell ISE with the Commands window open on the right, with the Get-MpComputerStatus cmdlet from the Defender module visible. I didn’t need to type a cmdlet; I just selected it from the list and then clicked Run.

screen-shot-2016-10-20-at-1-48-17-am

If you prefer a floating window instead of the docked pane, on the toolbar, click the Show Command Window button (second from the right). As screenshot shows, you can choose from the full selection of modules here, as well.
screen-shot-2016-10-20-at-1-49-30-am