我目前正在编写一个powershell脚本,要求提供一组管理员凭据,并使用这些凭据运行相关的应用程序,从网络托管的CSV中提取。当我尝试运行时
Start-Process $tools[$userInput-1].path.toString() -credential $credential
(其中$ tools返回“C:\ Program Files \ Microsoft \ Exchange Server \ V14 \ Bin \ Exchange Management Console.msc”)我收到以下错误
Start-Process : This command cannot be executed because the input "C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange Management Console.msc" is an Invalid Application. Give a valid application and Run your command again.
At line:1 char:14
+ Start-Process <<<< "C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange Management Console.msc" -credential
Get-Credential
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
如果我需要,我会写一个.bat文件并运行它,但我宁愿尽可能避免这种情况。
我不使用Invoke-Item的原因是因为它不能使用-Credential,即使man文件另有说明。
答案 0 :(得分:1)
.msc是一个已保存的控制台文件,其主机为mmc,因此要从powershell启动它,您可以使用类似于以下内容的语法:
$mmcPath = "C:\Windows\System32\mmc.exe"
$mscPath = "C:\Program Files\Microsoft\Exchange Server\V14\Bin\Exchange Management Console.msc"
Start-Process -FilePath $mmcPath -ArgumentList $mscPath