我目前正在编写一个 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 文件另有说明。