assorted recipes and links

See also: all the recipes and the intro

I have collected here the small groups of recipes and links that are not worthy a separate post each. As usual, some of the recipes are for cmd, some for PowerShell, guessing which is which is easy enough.

# Windows CMD command syntax

# To search inside e-mail message in Outlook:
* click on message to open it in a separate window
* press F4
# MSDN code gallery

# .CAB files
# Windows installer
# WDK image management
# bcdedit on WDK boot images
# BCD store description
# In Setup press Shift-F10 for command prompt

# Unattend.xml basic description
# Unattend.xml example with domain users
# unattend settings reference
# unattend OOBE settings

# software-defined networking
# technical details
# delete a driver altogether (use pnputil on Nano instead)
Devcon dp_delete
# NanoServer version of devcon is in \\winbuilds\release\rs1_release_svc_d\14300.1017.160621-1700\amd64fre\bin\mincore

# find or install the driver .inf files - normal way for NanoServer
pnputil.exe –e # to list all .inf files

# access a physical disk

# wipe out a file contents (in Sysinternals)
# Show the windows version
winver # in GUI
ver # in text
wmic os get version # works even on NanoServer
# from PowerShell
dir HKLM:\SOFTWARE\microsoft\windows*nt\currentversion

# Shutdown; "/t 0" would say to use the default timeout, not zero timeout
shutdown /s /t 1
shutdown /r /t 1 # reboot

# Disable the fast boot through hibernation (to avoid corruption on multi-boot systems)
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Power" /v HiberbootEnabled /t REG_DWORD /d 0 /f

# enabling and configuring features (like in the Server Manager, only command-line)
dism /online /get-features /format:table | findstr /i /c:"hyper"
dism /online /enable-feature /featurename:...

# generate a GUID
uuidgen.exe -c # to print, uppercase (uppercase required in many cases)
uuidgen -s # generate as a piece of C code

# register WMI provider (or other OLE services)
regsvr32 my.dll # register
regsvr32 /umy.dll # unregister

# get the list of the TCP listening processes
netstat -anb

# mounting a VHD in PowerShell
Mount-DiskImage -ImagePath $Vhd
try {
    # The object returned by "Mount-DiskImage" doesn't contain all the
    # information, so do the Get-DiskImage afresh.
    $vol = @(Get-DiskImage -ImagePath $Vhd | Get-Disk | Get-Partition | Get-Volume)
    if ($vol.Count -ne 1) {
        throw ("The VHD contains multipe volumes, don't know which one of [" + ($vol.DriveLetter -join ", ") + "] to use")
    Sleep 1 # looks like the mount is not immediate
    # ... use the mounted drive on $vol.DriveLetter ...
} finally {
    try {
        DisMount-DiskImage -ImagePath $Vhd
    } catch {
        Write-Verbose "Failed to dismount the disk image ${Vhd}:`r`n$_"

# DiskPart commands for VHD creation
# diskpart in general
# how to compact a VHD
# PATH and other settings in registry
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

# Installing the explorer GUI on server, if the server was not installed with full GUI
dism /online /enable-feature /featurename:Server-Gui-Shell
# same from PowerShell: 
Install-WindowsFeature -name Server-Gui-Shell

# enable Unicode UTF-8
chcp 65001
# back to English
chcp 437
# find the current code page
# In Visual Studio compiler either save files as "UTF-8 wihtout signature" or use
#pragma execution_character_set("utf-8") 
# (see )

# Changing the Public network types to Private
$networkListManager = [Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]"{DCB00C01-570F-4A9B-8D69-199FDBA5723B}"))
$connections = $networkListManager.GetNetworkConnections() 
$connections | % {if ($_.GetNetwork().GetCategory() -eq 0) { $_.GetNetwork().SetCategory(1)} }
$connections | % {$_.GetNetwork().GetCategory()} # read the results

# Performance monitor

# authenticating to another second domain
# offline domain join
# Creating the provisioning file for joining a domain
djoin /provision /reuse /domain redmond /machine mymachine /savefile c:\shared\mymachine-domain.txt
# applying the provisioning on the target - mount the \shared on x: before that
djoin /requestodj /loadfile x:\mymachine-domain.txt /windowspath e:\windows /localos  

# run as another user (even authenticated in a different domain)
runas /netonly /user:domain\username “C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe”`

# adding a domain user
net localgroup administrators redmond\sbabkin /add

# removing a password from administrator
net user administrator *

# registry place for finding Hyper-V and host information from a VM
hklm:SOFTWARE\Microsoft\Virtual Machine\Guest

# installing nanoServer directly to a disk from WIM,
# from
Select disk 0
Convert GPT
Create partition efi size=100
Format quick FS=FAT32 label="System"
Assign letter="s"
Create partition msr size=128
Create partition primary
Format quick FS=NTFS label="NanoServer"
Assign letter="n"
List volume
Dism.exe /apply-imagmediafile:.\NanoServer.wim /index:1 /applydir:n:\ Bcdboot.exe n:\Windows /s s:

# Installing extra packages
Install-PackageProvider NanoServerPackage
Import-PackageProvider NanoServerPackage
# also such as
Find-Package -provider NanoServerPackage
Get-Package -provider NanoserverPackage

# finding the DLL dependencies - a tool from Visual Studio
dumpbin /dependents myprogram.exe

# API scan tool
NanoServerApiScan.exe updated for TP5
# Depends.exe: depends.exe –w –e <your binary>
# How to remove the OneNote app
Get-AppxPackage *OneNote* | Remove-AppxPackage

# IMC configuration (loading of the extra machine-specific registry hives
# over the baseline registry).
# configuration for BCDBOOT (either on boot drive or on OS drive)
Bcdedit.exe /store %BCDStore% /set {default} imcdevice boot # if hive is on the boot drive
Bcdedit.exe /store %BCDStore% /set {default} imcdevice partition=%OSDrive% # if hive is on the OS drive
Bcdedit.exe /store %BCDStore% /set {default} imchivename %IMCHiveFile%

# PowerShell has a wget command!

# fix the line endings to CR-LF along with creating a private copy
Get-Content .\FabricConfig.psd1 | Set-Content MyFabricConfig.psd1

# Changing the network adapter configuration
# New- to set a new IP address, Set- to change the mask etc while keeping the IP address
Get-NetIPAddress -InterfaceAlias "vEthernet (SMB_2)" | New-NetIPAddress -IPAddress -PrefixLength 24

# open firewall for pinging
netsh advfirewall firewall add rule description="ICMPv4" profile=any action=allow name="ICMPv4"

# extract MSI file from a self-extracting exe
self_extracting.exe /s /x /b"C:\FolderInWhichMSIWillBeExtracted" /v"/qn"
lessmsi.exe x c:\tmp\MLNX_VPI.msi 
# see also msiexec
# Installer (msiexec) options
# how to extract an MSIexec file
# Lessmsi tool for extracting MSI
# Tool to expand the .CAB files, comes in ADK:
# For example:
# expand .\ -F:* tmp

# finding the update level
Get-WindowsPackage -Online | ? { $_.PackageName -match "Package_for_RollupFix" -and $_.PackageState -eq "Installed" }
# to enable RDP from command line
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f
netsh firewall set portopening protocol = TCP port = 3389 name = "Remote Desktop Protocol" mode=ENABLE

# installing 7zip, directly and from PowerShell # needs itself to unzip itself
Install-Package PS7Zip 

# WIM file format
# to create a WIM image, use

# Finding the SMBIOS GUID of a machine - UUID field

# Driver development (not very good but something)

# Mocks for testing in managed code .NET PowerShell

# Direct editing of resources in MUI files

# registry hive files in

# apply the .reg file silently
regedit /s file.reg

# show what command woke up Windows last time
powercfg -lastwake

# about winpeshl.ini and other tools available in the WinPE boot image

# Sysprep

# EMS SAC doc - serial console

# How to create an Active Directory Domain
# Domains and forests
# setting up a domain controller


Comments (0)

Skip to main content