首页 > 解决方案 > 尝试在 Powershell 中使用启动参数编写 .exe 脚本

问题描述

我是 PowerShell 的新手,我正在尝试创建一个脚本,该脚本将使用特定于此 .exe 文件的参数卸载 Dell Data Protection。

这是我减去我将使用的实际信用的内容:

Start-Process -Filepath C:\Programfiles (x86)\Dell\Dell Data Protection\DataSecurityUninstaller.exe" -argumentlist "CMG_DECRYPT=1 FORENSIC_ADMIN="ExampleUser" FORENSIC_PWD="Passw0rd" NOREBOOT /silent"

我得到:

A positional parameter cannot be found that accepts argument "ExampleUser" FORENSIC_PWD="Passw0rd" NOREBOOT

当我将它放入 CMD 时,它可以工作。我想我不知道如何正确处理运行参数。

标签: powershellscripting

解决方案


这些中的任何一个都应该起作用:

Start-Process -Filepath 'C:\Programfiles (x86)\Dell\Dell Data Protection\DataSecurityUninstaller.exe' -ArgumentList 'CMG_DECRYPT=1 FORENSIC_ADMIN="ExampleUser" FORENSIC_PWD="Passw0rd" NOREBOOT /silent'
Start-Process -Filepath 'C:\Programfiles (x86)\Dell\Dell Data Protection\DataSecurityUninstaller.exe' -ArgumentList 'CMG_DECRYPT=1', 'FORENSIC_ADMIN="ExampleUser"', 'FORENSIC_PWD="Passw0rd"', 'NOREBOOT', '/silent'

您在"此处打开"CMG然后在此处关闭,_ADMIN="这会导致 cmdlet 认为您将ExampleUser...其作为不同参数的输入,因此会出现错误。

此外,您可能只想从当前会话运行卸载程序,Start-Process在这种情况下不需要。我相信它会是这样的:

& 'C:\Programfiles (x86)\Dell\Dell Data Protection\DataSecurityUninstaller.exe' CMG_DECRYPT=1 FORENSIC_ADMIN="ExampleUser" FORENSIC_PWD="Passw0rd" NOREBOOT /silent

推荐阅读