使用提升的权限和传递的参数从cmd运行powershell脚本

使用提升的权限和传递的参数从cmd运行powershell脚本,powershell,batch-file,Powershell,Batch File,我正在尝试使用提升的权限从cmd运行powershell脚本,但我需要向powershell脚本传递一个参数。这是我正在使用的批处理文件的代码: echo off cls PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -Verb runas -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File &qu

我正在尝试使用提升的权限从cmd运行powershell脚本,但我需要向powershell脚本传递一个参数。这是我正在使用的批处理文件的代码:

echo off
cls
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -Verb runas -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dp0\MigrationTool.ps1 -ConfigFile ConfigFile.xml""'}"
当我使用上面的代码时,脚本什么也不做

如果我在没有-ConfigFile参数的情况下运行脚本,脚本将运行,然后它会提示我键入配置文件。虽然我得到提示,然后只是键入配置文件,但脚本仍然无法工作

我在互联网上做了一些挖掘,但找不到任何解决方案


谢谢。

我通常是这样做的:

@echo off

REM Calling script without parameters
REM powershell.exe -ExecutionPolicy Bypass -File E:\scripts\some-ps-script.ps1

REM Calling script with option 'Parameter'
powershell.exe -ExecutionPolicy Bypass -File "E:\scripts\some-ps-script.ps1" -Parameter
这应该适用于您的情况:

powershell.exe -ExecutionPolicy Bypass -File "E:\scripts\some-ps-script.ps1 -ConfigFile E:\scripts\ConfigFile.xml"

谢谢你的帮助,但我找到了解决问题的办法。 请参见下面其他人推荐的内容:

回音 cls

PowerShell.exe-NoProfile-ExecutionPolicy Bypass-Command“启动进程-文件路径PowerShell.exe-动词RunAs-ArgumentList'-NoProfile-ExecutionPolicy Bypass-文件“%~dp0MigrationTool.ps1”-配置文件“%~dp0ConfigFile.xml”


感谢您的帮助。

为什么要运行cmd来运行PowerShell来运行PowerShell?也许你的问题有一个不那么复杂的解决方案。您可以签出该工具。该问题可能是由双
引起的。cmd和powershell的转义方式不同。它没有提升为admin;)当然,你完全正确。我完全忽略了“特权提升的cmd”。