简体   繁体   中英

Powershell: Running a .msc applet as another user

I'm currently writing a powershell script that asks for a single set of admin credentials, and uses those to run relevant applications, pulled from a network-hosted CSV. When I try to run

Start-Process $tools[$userInput-1].path.toString() -credential $credential

(where $tools is returning "C:\\Program Files\\Microsoft\\Exchange Server\\V14\\Bin\\Exchange Management Console.msc") I get the error below

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

If I need to, I'll just write a .bat file and run that, but I'd rather avoid that whenever possible.

And the reason I'm not using Invoke-Item is because it can't take -Credential, even if the man file says otherwise.

.msc is a saved console file, the host of which is mmc , so to start this from powershell you could use syntax similar to the following:

$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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM