Convenience Scripts for Windows

ℹī¸ Active development of an OOBE PWSH script project over at https://github.com/aaanh/autowin. This project does most of the below and more.

Shut down a remote PC

shutdown -r -m \\MACHINE-NAME.<domain>.<tld>

Execution Policy ⚠ī¸

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
ExplanationBy default, the policy is set to Restricted: commands can be typed and run in the shell, but cannot run a script file. RemoteSigned is the minimal policy that allows it.

Virtualization Features ⚠ī¸

Required for: Windows Subsytems for Linux, Hyper-V, Docker

$win_features = "HypervisorPlatform", "VirtualMachinePlatform", "Microsoft-Windows-Subsystem-Linux", "Microsoft-Hyper-V-All", "Microsoft-Hyper-V", "Microsoft-Hyper-V-Tools-All", "Microsoft-Hyper-V-Management-Powershell", "Microsoft-Hyper-V-Hypervisor", "Microsoft-Hyper-V-Services", "Microsoft-Hyper-V-Management-Clients"

ForEach ($0 in $win_features) {
  Write-Host "Now installing $0..."
  dism /online /enable-feature /featurename:$0 /All /NoRestart
}

Disable 256-character path limit ⚠ī¸

a.k.a. Enable long path

New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" `
-Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force
ExplanationThe command is taken from Microsoft's Docs. It adds an entry to the registry (GUI accessible through regedit) which allows the long path.