Skip to content

Instantly share code, notes, and snippets.

@OddMorning
OddMorning / Run PowerShell from Batch (Full).cmd
Created February 9, 2024 13:33
Run PowerShell from Batch
/ 2>nul & @set "a=%* ''" & call set "a=%%a:"='%%"
@PowerShell -Command "$CMDScriptRoot = '%~dp0'; $CMDCommandPath = '%~f0'; ICM $([ScriptBlock]::Create((@('','') + $(Type '%~f0' | Select -Skip 2) | Out-String))) -Args $(echo %a%)" & exit /b
$e=[char]0x1b;"$e[2F$e[J$e[1F";rv e
Write-Host 🏠 Script path: $CMDCommandPath
Write-Host 🏠 Script dir: $CMDScriptRoot
Write-Host ✅ Argument 1: $($args[0])
Write-Host ✅ Argument 2: $($args[1])
###### Notes: