【发布时间】:2014-02-08 02:20:01
【问题描述】:
我猜测会使用 Start-Process,但我不确定如何同时完成这两件事。
用户是本地用户并且是管理员的成员。
此外,可能不需要用户输入。
更新:这是我尝试过的以及为什么它不起作用的原因。 正如基思建议的那样,我尝试执行以下操作:
$passwd = ConvertTo-SecureString -AsPlainText "opensesame" -Force
$cred = new-object system.management.automation.pscredential 'John',$passwd
Start-Process powershell.exe -credential $cred
这不会在管理员模式下启动 powershell 窗口。添加runas动词不起作用,因为start-process有two completely separate ways to call it,其中一个以-Verb为参数,其中一个以-Credential:
Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-Credential <PSCredential>] [-LoadUserProfile] [-NoNewWindow] [-PassThru] [-RedirectStandardError <string>] [-RedirectStandardInput <string>] [-RedirectStandardOutput <string>] [-UseNewEnvironment] [-Wait] [-WorkingDirectory <string>] [<CommonParameters>]
Start-Process [-FilePath] <string> [[-ArgumentList] <string[]>] [-PassThru] [-Verb <string>] [-Wait] [-WindowStyle {<Normal> | <Hidden> | <Minimized> | <Maximized>}] [-WorkingDirectory <string>] [<CommonParameters>]
这意味着以下返回错误:
Start-Process powershell.exe -credential $cred -verb runas
【问题讨论】:
标签: powershell