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
https://ss64.com/nt/syntax.html
# To search inside e-mail message in Outlook:
* click on message to open it in a separate window
* press F4
# MSDN code gallery
https://code.msdn.microsoft.com/
# .CAB files
https://msdn.microsoft.com/en-us/library/windows/desktop/aa367841%28v=vs.85%29.aspx
# Windows installer
https://msdn.microsoft.com/en-us/library/windows/desktop/aa372463%28v=vs.85%29.aspx
# WDK image management
https://technet.microsoft.com/en-us/library/cc732961%28v=ws.10%29.aspx
# bcdedit on WDK boot images
https://technet.microsoft.com/en-us/library/cc731245%28v=ws.10%29.aspx
# BCD store description
https://technet.microsoft.com/en-us/library/cc766223%28v=WS.10%29.aspx
# In Setup press Shift-F10 for command prompt
# Unattend.xml basic description
https://technet.microsoft.com/en-us/library/cc749317%28WS.10%29.aspx
# Unattend.xml example with domain users
https://blogs.msdn.com/b/matthew_van_eerde/archive/2012/03/15/unattend-xml-turning-on-remote-desktop-automatically.aspx
# unattend settings reference
https://msdn.microsoft.com/en-us/library/windows/hardware/dn922646(v=vs.85).aspx
# unattend OOBE settings
https://msdn.microsoft.com/en-us/library/windows/hardware/dn923212(v=vs.85).aspx
# software-defined networking
https://technet.microsoft.com/en-us/library/mt427380.aspx
# technical details
https://technet.microsoft.com/en-us/library/mt238303.aspx
# 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
xxd \\.\PHYSICALDRIVE0
# wipe out a file contents (in Sysinternals)
sdelete
# 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
https://technet.microsoft.com/en-us/library/gg252579.aspx
# diskpart in general
https://support.microsoft.com/en-us/kb/300415
# how to compact a VHD
https://blogs.technet.com/b/askcore/archive/2012/09/20/compacting-a-dynamically-expanding-virtual-hard-disk-in-windows-server-2012.aspx
# 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
chcp
# In Visual Studio compiler either save files as "UTF-8 wihtout signature" or use
#pragma execution_character_set("utf-8")
# (see https://stackoverflow.com/questions/688760/how-to-create-a-utf-8-string-literal-in-visual-c-2008 )
# Changing the Public network types to Private
https://blogs.msdn.com/b/powershell/archive/2009/04/03/setting-network-location-to-private.aspx
$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
perfmon.exe
# offline domain join
djoin.exe
# 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)
https://serverfault.com/questions/84417/joining-multiple-domains-in-windows-7
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 https://technet.microsoft.com/windows-server-docs/compute/nano-server/getting-started-with-nano-server
Diskpart.exe
Select disk 0
Clean
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
Exit
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
Find-NanoServerPackage
Save-NanoServerPackage
Install-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
https://blogs.technet.microsoft.com/nanoserver/2016/04/27/nanoserverapiscan-exe-updated-for-tp5/
# Depends.exe:
https://technet.microsoft.com/en-us/library/cc738370(v=ws.10).aspx
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 192.168.11.14 -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
https://msdn.microsoft.com/en-us/library/windows/desktop/aa367988%28v=vs.85%29.aspx
# how to extract an MSIexec file
https://superuser.com/questions/307678/how-to-extract-files-from-msi-package
https://stackoverflow.com/questions/1547809/extract-msi-from-exe
# Lessmsi tool for extracting MSI
https://lessmsi.activescott.com/
# Tool to expand the .CAB files, comes in ADK:
# For example:
# expand .\Microsoft-NanoServer-Compute-Package.cab -F:* tmp
https://technet.microsoft.com/en-us/library/dd744339%28v=ws.10%29.aspx
# finding the update level
Get-WindowsPackage -Online | ? { $_.PackageName -match "Package_for_RollupFix" -and $_.PackageState -eq "Installed" }
# to enable RDP from command line
# https://www.windows-commandline.com/enable-remote-desktop-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
https://www.7-zip.org/a/7z1602-extra.7z # needs itself to unzip itself
Install-Package PS7Zip
# WIM file format
https://technet.microsoft.com/en-us/library/cc749478%28v=WS.10%29.aspx
# to create a WIM image, use
imagex.exe
# Finding the SMBIOS GUID of a machine - UUID field
https://msdn.microsoft.com/en-us/library/aa394105%28v=vs.85%29.aspx
# Driver development (not very good but something)
https://www.codeproject.com/Articles/9504/Driver-Development-Part-1-Introduction-to-Drivers
# Mocks for testing in managed code .NET PowerShell
https://github.com/Moq/moq4
# Direct editing of resources in MUI files
https://superuser.com/questions/760948/wordpad-in-win-7-how-to-change-the-default-font-and-size
https://www.angusj.com/resourcehacker/
https://www.wilsonc.demon.co.uk/d10resourceeditor.htm
# registry hive files in
C:\windows\system32\config
# apply the .reg file silently
# https://support.microsoft.com/kb/310516
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
https://technet.microsoft.com/en-us/library/cc766156%28v=WS.10%29.aspx
# Sysprep
c:\Windows\System32\Sysprep\sysprep.exe
# EMS SAC doc - serial console
https://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/WindowsServer2003EMSSACXML.doc
# How to create an Active Directory Domain
https://support.microsoft.com/kb/324753
https://technet.microsoft.com/en-us/library/jj574166.aspx
# Domains and forests
https://technet.microsoft.com/en-us/library/cc759073%28v=WS.10%29.aspx
# setting up a domain controller
https://www.elmajdal.net/WindowsServer/Setting_Up_Your_First_Active_Directory_Domain_Controller_With_Windows_Server_2012.aspx