powershell -noexit & “C:\script.ps1”
@Echo Off
PowerShell.exe -Command "Invoke-Expression -Command ((Get-Content -Path '%~f0' | Select-Object -Skip 3) -join [environment]::NewLine)"
Exit /b %ErrorLevel%
## Powershell starts here
Write-Host "Hello World"
whoami /groups | find "S-1-16-12288" >nul || (echo *** Not running elevated - STOP *** & pause & exit /b 1)
In your batch file simply put a line in the cmd script calling the PowerShell like this:
Open in new window
Usually I like to create a wrapper script file with the same name as the PowerShell script so that I can run it and log the output to a file similar to below:
Open in new window