# 관리자 권한 확인 if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Warning "이 스크립트를 실행하려면 관리자 권한이 필요합니다." Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs exit } echo "Hello PowerShell" Write-Output "Hello PowerShell" Write-Host "Hello PowerShell"
윈도우 cmd 에서는 아래와 같이 실행한다.
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ".\test.ps1"