Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for bootstate.ps

(view source code of bootstate.ps as plain text)

  1. param( [string]$arg = "" )
  2.  
  3. if ( ( $arg -ne "" ) -or ( $HOME[0] -eq "/" ) ) {
  4. 	Write-Host
  5. 	Write-Host "BootState.ps1,  Version 1.00"
  6. 	Write-Host "Show Windows' boot state"
  7. 	Write-Host
  8. 	Write-Host "Usage:    PowerShell . 'BootState.ps1'"
  9. 	Write-Host
  10. 	Write-Host "Notes:    Boot State is returned as string and as return code (`"errorlevel`"):"
  11. 	Write-Host "              `"Normal`"                    (errorlevel = 0)"
  12. 	Write-Host "              `"Safe mode`"                 (errorlevel = 1)"
  13. 	Write-Host "              `"Safe mode with network`"    (errorlevel = 2)"
  14. 	Write-Host "              `"Windows PE`"                (errorlevel = 3)"
  15. 	Write-Host "          In case of (command line) errors, the errorlevel will be -1."
  16. 	Write-Host "          This script is written for Windows only."
  17. 	Write-Host
  18. 	Write-Host "Credits:  Windows PE detection based on a tip by Mitch Tulloch"
  19. 	Write-Host "          http://techgenix.com/HowtodetectwhetheryouareinWindowsPE/"
  20. 	Write-Host
  21. 	Write-Host "Written by Rob van der Woude"
  22. 	Write-Host "http://www.robvanderwoude.com"
  23. 	Write-Host
  24. 	exit -1
  25. }
  26.  
  27. if ( Test-Path "HKLM:\SYSTEM\ControlSet001\Control\MiniNT" ) {
  28. 	Write-Host "Windows PE"
  29. 	exit 3
  30. }
  31.  
  32. foreach ( $computer in Get-WmiObject -Class Win32_ComputerSystem ) {
  33. 	switch ( $computer.BootupState ) {
  34. 		"Normal boot" {
  35. 			Write-Host "Normal"
  36. 			exit 0
  37. 		}
  38. 		"Fail-safe boot" {
  39. 			Write-Host "Safe mode"
  40. 			exit 1
  41. 		}
  42. 		"Fail-safe with network boot" {
  43. 			Write-Host "Safe mode with network"
  44. 			exit 2
  45. 		}
  46. 	}
  47. }
  48.  
  49. Write-Host "Unknown"
  50. exit -1
  51.  

page last modified: 2024-04-16; loaded in 0.0226 seconds