将ThisScriptsDirectory作为参数从批处理传递到Powershell

时间:2015-11-25 23:59:21

标签: powershell batch-file parameters

我已经查看了几个不同的解决方案,主题是使用批处理文件将参数传递到Powershell脚本中;但是他们都没有为我工作。我的批次比我看到的其他问题要复杂一些,经过多次搜索,我决定发布自己的。

这是我当前的批处理文件(运行但未传入参数):

@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脚本中。

1 个答案:

答案 0 :(得分:0)

如果您只需要访问环境变量的值,可以在Powershell脚本中通过PSDrive获取环境变量。

基于批处理文件的示例。

$ENV:ThisScriptsDirectory
$ENV:PowerShellScriptPath