Windows Server 2019’s command line isn’t just an option—it’s the backbone of administration, automation, and troubleshooting. From managing files and services to configuring network settings and auditing system health, the PowerShell and traditional command-line interface (CLI) tools give you precise control over your server environment. This guide covers the core commands you’ll need, practical examples, and how to avoid common pitfalls.
What You'll Need
- Windows Server 2019 installed and running (preferably in a virtual machine for testing).
- Administrator privileges—most commands require elevated access.
- A text editor (like Notepad or VS Code) for scripting if you’re creating custom commands.
- An internet connection to verify updates or download tools.
- Basic familiarity with file systems, network interfaces, and core server roles (Active Directory, DHCP, etc.). If you’re new to server administration, start with foundational concepts like logging in, checking system status, and viewing disk space.
Step-by-Step Guide to Windows Server 2019 Command Line Basics
- Accessing the Command Line Interface (CLI)
- On Windows Server 2019, press
Win + R, typecmd, and hit Enter to open the Command Prompt. - For PowerShell (more powerful but similar syntax), type
powershellinstead. - To switch to Administrator mode (if needed), right-click the Command Prompt/PowerShell icon, select Run as administrator, and confirm with your credentials.
Tip: The CLI is case-sensitive in PowerShell but not in traditional Command Prompt.
- On Windows Server 2019, press
- Essential Command-Line Shortcuts
- Navigate files and directories:
cd \to go to the root directory.cd C:\Windows\to navigate to the Windows system folder.ls(PowerShell) ordir(Command Prompt) to list files/directories.
- Check system information:
systeminfo(Command Prompt) or$env:COMPUTERNAME(PowerShell) to see server name and details.ps(PowerShell) ortasklist(Command Prompt) to list running processes.
- View logs and services:
query service *to list all services.eventvwr.msc(open Event Viewer) orw32tm /query /showsettingsto check time sync settings.
- Navigate files and directories:
- File System Management
- Copy, move, and delete files:
copy source.dst(Command Prompt) orCopy-Item source.dst(PowerShell).move src dest(Command Prompt) orMove-Item src dest(PowerShell).del file.txt(Command Prompt) orRemove-Item file.txt(PowerShell).
- Create folders:
mkdir newfolder(Command Prompt) orNew-Item -ItemType Directory -Name newfolder(PowerShell).
- Check disk space:
wmic logicaldisk get size,freespace,caption(Command Prompt) orGet-PSDrive -PSProvider FileSystem(PowerShell).
- Copy, move, and delete files:
- Network Configuration
- View and manage network adapters:
ipconfig /allto show all network interfaces and details (IPv4/IPv6, DNS, gateway).netsh interface show interfaceto list active network connections.
- Configure static IP settings:
- Open
Network and Sharing Center, click Change adapter settings, right-click your adapter, choose Properties, and add IPv4/IPv6 settings manually if needed. - Use
netsh interface ip set address "Name" static 192.168.1.100 255.255.255.0 192.168.1.1for PowerShell (requires admin rights).
- Open
- Test connectivity:
ping google.comto test internet reachability.test-connection -ComputerName server.example.com(PowerShell) to check remote server.
- View and manage network adapters:
- System Services and Processes
- Start, stop, and manage services:
net start servicenameto start a service.net stop servicenameto stop a service.sc query servicenameto check service status.
- List running processes:
tasklist(Command Prompt) orGet-Process(PowerShell).
- Check disk usage by process:
wmic process where "name='explorer.exe'" get WorkingSet, CommandLine(limited use; better to use Process Explorer from Microsoft).
- Start, stop, and manage services:
- Automation with PowerShell
- Create a simple script to back up files:
- Open PowerShell, type
New-Variable -Name "BackupPath" -Value "C:\Backups", then useGet-ChildItem C:\Data -Recurse | Copy-Item -Destination $BackupPathto copy all files from C:\Data to C:\Backups.
- Open PowerShell, type
- Use conditional logic:
- Example:
if ($host.RunspacesDefaultParallelization -gt 0) { Write-Host "Parallel mode enabled." } else { Write-Host "Single-threaded." }
- Example:
Note: Always save PowerShell scripts as .ps1 files and run them in an elevated PowerShell session.
- Create a simple script to back up files:
Common Mistakes
- Running commands as non-admin—most system-related commands (e.g., `netsh`, `sc`, `net start`) require administrative privileges. If you encounter "access denied," reboot into Safe Mode with networking or use an admin account.
- Typo-induced errors—Windows CLI is case-sensitive. For example, `
get-service` (PowerShell) won’t work unless spelled exactly—always double-check command names and parameters. - Overwriting critical system files—avoid deleting or modifying files in
C:\WindowsorC:\Program Fileswithout first understanding their purpose. Userobocopyinstead ofxcopyfor safe file transfers. - Ignoring output warnings—commands like
diskpartorroute addmay prompt for confirmation. If you ignore prompts, you might lose data or misconfigure the system. Always read error messages.
Tips
- Use shortcuts—press
Ctrl+Shift+Enterto run PowerShell commands directly in Notepad without pasting. This saves time for quick scripts. - Create aliases—in PowerShell, create aliases like
alias ls="Get-ChildItem"to save typing. - Backup your server before making major CLI changes. Use
robocopyto copy critical folders orVSSAdminfor volume shadow copies. - Leverage online help—type
help(e.g.,help net start) in Command Prompt orGet-Helpin PowerShell for full documentation.-Detailed - Script for automation—save frequently used commands in a `.txt` file and edit it directly. For PowerShell, use
Set-ExecutionPolicy RemoteSignedto allow running scripts securely.
Troubleshooting
- Command not recognized
- Ensure you’re using the correct version of the command. For example,
Get-Serviceis PowerShell; useservices.mscin GUI mode. - Restart Command Prompt/PowerShell—sometimes cached commands fail.
- Check if your PowerShell module is installed. Use
Get-Module -ListAvailableto see installed modules.
- Ensure you’re using the correct version of the command. For example,
- Permission denied
- Run the command in an elevated session (as admin).
- If the issue persists, check the specific folder’s permissions. Right-click the folder, go to Security, and ensure your user account has Full Control.
- Network-related errors
- Verify the interface name. Use
ipconfig /allto confirm the correct adapter name (e.g.,EthernetorWi-Fi). - Reset TCP/IP stack:
netsh int ip reset. - Restart the network service:
net stop TCPIP && net start TCPIP.
- Verify the interface name. Use
- Disk or service not found
- Check the exact drive/name. For example,
sc query winrmshows the service name. If missing, reinstall the service fromservices.mscor viaAdd-WindowsFeature Windows-Server-Management(PowerShell). - For missing files, reinstall Windows Server 2019 or restore from a backup.
- Check the exact drive/name. For example,
Frequently Asked Questions
How do I check if a service is running on Windows Server 2019?
Use sc query servicename in Command Prompt or Get-Service -Name "servicename" in PowerShell. Replace servicename with the actual service (e.g., Get-Service EventLog to check the Windows Event Log service).
Can I use traditional Windows CLI commands in PowerShell?
Most traditional commands work in PowerShell if you use their PowerShell equivalents. For example, ipconfig in Command Prompt becomes $env:COMPUTERNAME, but ping remains ping. Some commands are dropped; avoid them in PowerShell.
What’s the difference between Command Prompt and PowerShell in Windows Server 2019?
Command Prompt is simpler and retains older syntax (e.g., net start for services). PowerShell is more powerful, supports scripting, and integrates with object models (e.g., Get-Service returns objects instead of text). Use PowerShell for automation, Command Prompt for quick tasks.
How do I clear the event log manually via CLI?
Use wevtutil cl application to clear the Application log. For all logs, use wevtutil cl. Replace application with the specific log name if needed (e.g., system for System log).
How can I create a simple script to back up a folder?
In PowerShell, use this script to back up C:\Data to C:\Backup\DataBackup_$(Get-Date -Format "yyyyMMdd").zip:
$source = "C:\Data"
$backup = "C:\Backup\DataBackup_$(Get-Date -Format "yyyyMMdd").zip"
Compress-Archive -Path $source -DestinationPath $backup -Force
Save it as a .ps1 file and run in an elevated PowerShell session.
What if I accidentally delete a critical system file?
Windows Server 2019 has built-in recovery tools. Restart the server in Safe Mode with Networking (hold Shift while rebooting), then use sfc /scannow (System File Checker) to repair corrupted files. If the issue persists, restore from a backup (use wpeutil in PowerShell for the last known good state).