Menu
HomeKBHow-to for AdminsConsole | Useful Commands for CMD, PS, Win PE and CLI

Console | Useful Commands for CMD, PS, Win PE and CLI

On this page you may find some useful commands for different tasks in Windows Command Prompt (CMD), Powershell (PS), Windows Preinstallation Environment (Windows PE) and Command Line Interface (CLI). Most commands have been used on the following operating systems:

CMD, PS and Win PE with

  • Windows 8.1
  • Windows 10
  • Windows Server 2012 R2

CLI with the Linux distributions

  • CentOS
  • Debian
  • Knoppix
  • Red Hat
  • Ubuntu

 


Windows CMD

Common System Commands

Restart (/r), shutdown (/s) or logoff (/l) a Windows system within 1 second after execution
C:\> shutdown /r /t 1
C:\> shutdown /s /t 1
C:\> shutdown /l /t 1

Windows Firewall Commands

Quickly turning ON/OFF Windows Firewall
C:\> Netsh Advfirewall show allprofiles
C:\> NetSh Advfirewall set allprofiles state off
C:\> NetSh Advfirewall set allprofiles state on

DFS Maintenance

Show specific DFS namespace root and its links
Syntax:  dfsutil root \\<Domain>\<Namespace>
Example: dfsutil root \\dev.beontec.eu\Sites
Check DFS namespace integrity
Syntax:  dfsdiag /testdfsintegrity /dfsroot:\\<Domain>\<Namespace>
Example: dfsdiag /testdfsintegrity /dfsroot:\\dev.beontec.eu\Sites

 You would like to see a result similar to this one:

Starting TestDfsIntegrity...

Validating the DFS metadata integrity of \\DEV\Sites...
Success: No known corruption is found in the DFS metadata.
Checking for DFS metadata consistency between domain controllers and the PDC emu
lator in the domain...
Success: DFS metadata is consistent across all accessible domain controllers and
 the PDC emulator.

Checking the registry of the namespace servers...
Success: Registry information on namespace servers is consistent with the metada
ta in Active Directory Domain Services.

Validating reparse points of all DFS folders in namespace: \\DEV\Sites
Finished TestDfsIntegrity.

DFSR Maintenance

Check DFSR replication status

If you would like to see current files to be in sync (processing and scheduled) by DFS replication you can do this by opening PowerShell on a domain member with havinh DFS management tools (feature) installed and executing:

Syntax:  .\dfsrdiag.exe ReplicationState /mem:<Hostname>
Example: .\dfsrdiag.exe ReplicationState /mem:SRV-FS2
Manually start DFSR synchronization between two servers
Dfsrdiag SyncNow /partner:dfsserver2 /rgname:domainname\spacename\folder1 /member:dfsserver1 /time:5
Dfsrdiag SyncNow /partner:SRV-FS2 /rgname:mydomain.intern\corp\documents /member:SRV-FS1 /time:5

Network Card Management

Disable (re-enable) IPv6 stack
netsh int ipv6 isatap set state disabled (enabled)
netsh int ipv6 6to4 set state disabled (enabled)
netsh interface teredo set state disable (default)

 


Windows Powershell

File Management

Get overview about all mounted partitions with Get-PSDrive (alias: gdr)
PS > gdr -PSProvider 'FileSystem'
Check Windows file system with auto answer 'yes' and reboot system
PS > Echo y | chkdsk /x /v c:
PS > shutdown /r /t 1
Force a CHKDSK at system boot for other partitions by marking them dirty (only NTFS)
fsutil dirty set D:

Query whether the drives have been marked as dirty

fsutil dirty query D:
Search for CHKDSK results in the Windows Event Viewer

After CHKDSK has finished the system will reboot automatically. You may find the results in the Event Viewer > Windows Logs > Applications > Filter Current Log... and set Event Source to Wininit and <All Event IDs> to 1001.

The result will look similar to this one:

Checking file system on C:
The type of the file system is NTFS.
Volume label is System.


A disk check has been scheduled.
Windows will now check the disk.

Stage 1: Examining basic file system structure ...
Cleaning up instance tags for file 0x90e7.
326400 file records processed. File verification completed.
13005 large file records processed. 0 bad file records processed.
Stage 2: Examining file name linkage ...
430740 index entries processed. Index verification completed.
0 unindexed files scanned. 0 unindexed files recovered.
Stage 3: Examining security descriptors ...
Cleaning up 1577 unused index entries from index $SII of file 0x9.
Cleaning up 1577 unused index entries from index $SDH of file 0x9.
Cleaning up 1577 unused security descriptors.
Security descriptor verification completed.
52171 data files processed. CHKDSK is verifying Usn Journal...
Usn Journal verification completed.
CHKDSK discovered free space marked as allocated in the volume bitmap.

Windows has made corrections to the file system.
No further action is required.

78281727 KB total disk space.
70630948 KB in 257174 files.
169156 KB in 52172 indexes.
0 KB in bad sectors.
401675 KB in use by the system.
65536 KB occupied by the log file.
7079948 KB available on disk.

4096 bytes in each allocation unit.
19570431 total allocation units on disk.
1769987 allocation units available on disk.

Internal Info:
00 fb 04 00 6c b8 04 00 82 46 09 00 00 00 00 00 ....l....F......
a2 01 00 00 a4 00 00 00 00 00 00 00 00 00 00 00 ................

Windows has finished checking your disk.
Please wait while your computer restarts.

 

How to install additional Windows Server 2012 R2 Features

Install .NET Framework 3.5 (incl. 2.0) on Windows Server 2012 R2 by using Windows PowerShell

There are two options: installing directly from install medium or using a network path. Mount the Windows Server 2012 R2 installation medium (e.g. drive letter E:) and specify the source path manually.

Option 1: use install medium as source
Install-WindowsFeature Net-Framework-Core -source E:\sources\sxs
Option 2: use network share as source

Copy the SxS folder (E:\sources\sxs) to a network location.

Install-WindowsFeature Net-Framework-Core -source \\network\share\sxs

 


Windows PE

Before you perform any maintenance tasks in Windows Preinstall Environment make sure your hard disks are attached to a storage controller or HBA where Windows has the drivers. Example: In case you run your VMware VMs with a SCSI controller of the type 'VMware Paravirtual' you need to switch them back to the type 'LSI Logic SAS'. Windows PE does not include the Paravirtual driver and will not see any hard disks.

Recover Windows after boot failure

Boot from Windows installation disk (Windows 7 and Windows Server 2008 R2 upwards)

X:\Sources> sfc /scannow

Use the full command if you get the error message "there is a system repair pending which requires reboot to complete":

X:\Sources> sfc /scannow /OffBootDir=C:\ /OffWinDir=C:\Windows

Check file system integrity

 X:\Sources> chkdsk /x /v c:
Show up boot menu in Windows Vista and Windows Server 2012 upwards to enable F8 during boot

When having access to the boot menu you are able to choose between several boot options:

  • Repair Your Computer
  • Safe Mode - Safe Mode with Networking - Safe Mode with Command Prompt
  • Enable Boot Logging
  • Enable low-resolution video (640x480)
  • Directory Services Restore Mode
  • Debugging Mode
  • Disable automatic restart on system failure
  • Disable Driver Signature Enforcement
  • Start Windows Normally

In the command prompt of the Win PE execute:

X:\Sources> bcdedit /set {bootmgr} displaybootmenu yes
X:\Sources> bcdedit /set {bootmgr} timeout 10

If you only execute line 1 the system will continue the boot after 30 seconds of waiting for user input.

Using 'Last Known Good' in the boot menu

"In the system’s registry, the system’s configuration settings are stored under HKLM\System\CurrentControlSet\Control along with driver and service configurations stored under HKLM\System\CurrentControlSet\Services. Any change to these locations in the registry can render the system unbootable. If you happen to be in a situation where you are unable to boot into your Windows operating system normally, your system may have encountered a damaging change to the system’s registry prior to its last shutdown or reboot. In order to troubleshoot the issue, you have the opportunity to boot into the Last Known Good option by hitting F8 during the boot process. This will bring you to the Windows Advanced options Menu screen as shown below."

Source: https://blogs.technet.microsoft.com/askcore/2011/08/05/last-known-good/

 


Linux CLI

Restart (-r) or shutdown (-h) Linux system
# shutdown -r now
# shutdown -h now
Repair Linux file systems with fsck (e2fsck) manually in offline mode

In case you experience any issues with any of your Linux systems like VMware VCSA, vROps, vCOps, Apache webserver 

  1. Live boot KNOPPIX from installation medium
    Source: http://www.knopper.net/knoppix-mirrors/
  2. Run terminal

To check disks and raid arrays attached:

# fdisk -l | less

To get an overview about the file system types (Linux, swap) of attached devices:

# cat /proc/mounts
# ls /mnt

To get an overview about the file systems (ext4, ext3 and xfs) of attached devices:

# blkid

To check and repair (-f) an ext4 formatted file system.
!! The devices need to be unmounted! Don't try to repair mounted devices. There is a high chance to damage the file system even further !!

# fsck.ext4 -f /dev/sda1
# e2fsck -f /dev/sda1

To check a swap disk for bad blocks in verbose mode (-v) and output bad sectors detected

# badblocks -v /dev/sda2
IT Service for the United States of America in Germany IT Service Provider in Germany IT Service for the Philippines in Germany IT Service for Australia in Germany
Go to top