Detecting WinPE

by Aug 29, 2018

PowerShell can run inside WinPE environments. If you’d like to detect whether your PowerShell script runs inside a WinPE environment, you can simply check whether a special registry key exists:

function Test-WinPE
{
  return Test-Path -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlset\Control\MiniNT
}

This function returns $true if you are within a WinPE environment.

Twitter This Tip! ReTweet this Tip!