Advertisement
Couleur

Bat2PowerShell (argument passthru)

Nov 3rd, 2021
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. <# : Start of the batch script, perceived as a comment in PowerShell
  2. @echo off
  3. DEL %temp%\input.txt
  4. set argCount=0
  5. :: For loop that puts every input args in a temp text file
  6. for %%x in (%*) do (
  7. set /A argCount+=1
  8. echo %%~x >> %temp%\input.txt
  9. )
  10.  
  11. :: Opens itself as PowerShell
  12. pwsh.exe -noexit -c "iex (${%~f0} | out-string)"
  13. #>
  14.  
  15. [array]$Arguments = Get-Content "$env:TMP\input.txt"
  16.  
  17. $Arguments # And there you go, some fancy args ready to use in an array! :)
  18.  
  19. pause <# the only downside with this is that the VSCode extension bugs out and thinks there's an error at the end#>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement