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

  1. Accessing the Command Line Interface (CLI)
    1. On Windows Server 2019, press Win + R, type cmd, and hit Enter to open the Command Prompt.
    2. For PowerShell (more powerful but similar syntax), type powershell instead.
    3. 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.

  2. Essential Command-Line Shortcuts
    1. Navigate files and directories:
      • cd \ to go to the root directory.
      • cd C:\Windows\ to navigate to the Windows system folder.
      • ls (PowerShell) or dir (Command Prompt) to list files/directories.
    2. Check system information:
      • systeminfo (Command Prompt) or $env:COMPUTERNAME (PowerShell) to see server name and details.
      • ps (PowerShell) or tasklist (Command Prompt) to list running processes.
    3. View logs and services:
      • query service * to list all services.
      • eventvwr.msc (open Event Viewer) or w32tm /query /showsettings to check time sync settings.
  3. File System Management
    1. Copy, move, and delete files:
      • copy source.dst (Command Prompt) or Copy-Item source.dst (PowerShell).
      • move src dest (Command Prompt) or Move-Item src dest (PowerShell).
      • del file.txt (Command Prompt) or Remove-Item file.txt (PowerShell).
    2. Create folders:
      • mkdir newfolder (Command Prompt) or New-Item -ItemType Directory -Name newfolder (PowerShell).
    3. Check disk space:
      • wmic logicaldisk get size,freespace,caption (Command Prompt) or Get-PSDrive -PSProvider FileSystem (PowerShell).
  4. Network Configuration
    1. View and manage network adapters:
      • ipconfig /all to show all network interfaces and details (IPv4/IPv6, DNS, gateway).
      • netsh interface show interface to list active network connections.
    2. 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.1 for PowerShell (requires admin rights).
    3. Test connectivity:
      • ping google.com to test internet reachability.
      • test-connection -ComputerName server.example.com (PowerShell) to check remote server.
  5. System Services and Processes
    1. Start, stop, and manage services:
      • net start servicename to start a service.
      • net stop servicename to stop a service.
      • sc query servicename to check service status.
    2. List running processes:
      • tasklist (Command Prompt) or Get-Process (PowerShell).
    3. Check disk usage by process:
      • wmic process where "name='explorer.exe'" get WorkingSet, CommandLine (limited use; better to use Process Explorer from Microsoft).
  6. Automation with PowerShell
    1. Create a simple script to back up files:
      • Open PowerShell, type New-Variable -Name "BackupPath" -Value "C:\Backups", then use Get-ChildItem C:\Data -Recurse | Copy-Item -Destination $BackupPath to copy all files from C:\Data to C:\Backups.
    2. Use conditional logic:
      • Example: if ($host.RunspacesDefaultParallelization -gt 0) { Write-Host "Parallel mode enabled." } else { Write-Host "Single-threaded." }

    Note: Always save PowerShell scripts as .ps1 files and run them in an elevated PowerShell session.

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:\Windows or C:\Program Files without first understanding their purpose. Use robocopy instead of xcopy for safe file transfers.
  • Ignoring output warnings—commands like diskpart or route add may 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+Enter to 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 robocopy to copy critical folders or VSSAdmin for volume shadow copies.
  • Leverage online help—type help (e.g., help net start) in Command Prompt or Get-Help -Detailed in PowerShell for full documentation.
  • Script for automation—save frequently used commands in a `.txt` file and edit it directly. For PowerShell, use Set-ExecutionPolicy RemoteSigned to allow running scripts securely.

Troubleshooting

  1. Command not recognized
    1. Ensure you’re using the correct version of the command. For example, Get-Service is PowerShell; use services.msc in GUI mode.
    2. Restart Command Prompt/PowerShell—sometimes cached commands fail.
    3. Check if your PowerShell module is installed. Use Get-Module -ListAvailable to see installed modules.
  2. Permission denied
    1. Run the command in an elevated session (as admin).
    2. 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.
  3. Network-related errors
    1. Verify the interface name. Use ipconfig /all to confirm the correct adapter name (e.g., Ethernet or Wi-Fi).
    2. Reset TCP/IP stack: netsh int ip reset.
    3. Restart the network service: net stop TCPIP && net start TCPIP.
  4. Disk or service not found
    1. Check the exact drive/name. For example, sc query winrm shows the service name. If missing, reinstall the service from services.msc or via Add-WindowsFeature Windows-Server-Management (PowerShell).
    2. For missing files, reinstall Windows Server 2019 or restore from a backup.

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).