将 ThisScriptsDirectory 作为参数从 Batch 传递到 Powershell
Passing ThisScriptsDirectory as a Parameter into Powershell from Batch
关于使用批处理文件将参数传递到 Powershell 脚本的主题,我查看了几个不同的解决方案;但是 none 对我来说非常有用。我的批次比我看到的 posted 的其他问题稍微复杂一点,经过大量搜索后,我决定 post 我自己的。
这是我当前的批处理文件(运行,但不传入参数):
@ECHO OFF
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%TrentsAdobeTool1.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs"};
pause
我正在尝试将 ThisScriptsDirectory 作为参数传递给提到的脚本,存储它,并能够将其用作路径(稍后将其他文件夹添加到路径)
所以,我想知道如何更改批处理文件,以及如何将参数接受到 Powershell 脚本中。
如果您只需要访问环境变量的值,您可以通过 PSDrive for environment variables 在 Powershell 脚本中执行此操作。
示例基于您的批处理文件。
$ENV:ThisScriptsDirectory
$ENV:PowerShellScriptPath
关于使用批处理文件将参数传递到 Powershell 脚本的主题,我查看了几个不同的解决方案;但是 none 对我来说非常有用。我的批次比我看到的 posted 的其他问题稍微复杂一点,经过大量搜索后,我决定 post 我自己的。
这是我当前的批处理文件(运行,但不传入参数):
@ECHO OFF
SET ThisScriptsDirectory=%~dp0
SET PowerShellScriptPath=%ThisScriptsDirectory%TrentsAdobeTool1.ps1
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%PowerShellScriptPath%""' -Verb RunAs"};
pause
我正在尝试将 ThisScriptsDirectory 作为参数传递给提到的脚本,存储它,并能够将其用作路径(稍后将其他文件夹添加到路径)
所以,我想知道如何更改批处理文件,以及如何将参数接受到 Powershell 脚本中。
如果您只需要访问环境变量的值,您可以通过 PSDrive for environment variables 在 Powershell 脚本中执行此操作。
示例基于您的批处理文件。
$ENV:ThisScriptsDirectory
$ENV:PowerShellScriptPath