使用批处理文件中的参数运行Powershell

问题描述 投票:0回答:1

为了方便使用,我需要将我的powershell脚本放在bat文件中。 bat文件内容如下:

# 2>NUL & @CLS & PUSHD "%~dp0" & powershell -COMMAND "Start-Process powershell -Verb RunAs -ArgumentList '-windowstyle hidden -nol -nop -ep bypass ""[IO.File]::ReadAllText(''%~f0'')|iex""'"
# powershell script

但是,在powershell脚本中,我需要获取bat文件的路径。我知道我可以通过 'SET "batFilePath=%~f0"' 获取完整路径...但我不知道接下来应该做什么才能在 powershell 脚本中传入并使用 batFilePath 参数。请帮助我,非常感谢。

P/s:并不是我懒,我尝试寻找类似的主题,但答案对我来说都很混乱,我不知道在我的情况下该怎么办。对不起。

powershell cmd arguments
1个回答
0
投票
# 2>NUL & @CLS & PUSHD "%~dp0" & SET "batFilePath=%~f0" & powershell -Command "$batFilePath = $env:batFilePath; Start-Process powershell -Verb RunAs -ArgumentList ""-windowstyle hidden -nol -nop  Invoke-Expression (Get-Content -Path $env:batFilePath -Raw)"""
© www.soinside.com 2019 - 2024. All rights reserved.