开发者

Powershell Start-job new window run as administrator

I have script which write some COMMAND to another script and start them in new window with Start-Job command (I really need that). $cred is credential of local administrator. Main script started from powershell windows which opened "run as administrator" (as machine administrator). COMMAND need to open with machine administrator account (like new window open with "run as administrator"). BUT new window open only with local administrator rights. I search in the internet for information to round this issue, but failed. May be someone know how i can run new window with start-job command with machine administrator ("run as administrator")?

$ScriptFile = "$env:TEMP\ScriptBlock.ps1"
Write-Output "`$ProfileApp = <COMMAND> | Out-File $ScriptFile -Width 300
$PJob = Start-Job -Name PJob -Credential $cred -FilePath $ScriptFile -Verbose -InitializationScript {Add-PsSnapin Microsoft.SharePoint.PowerShell} | Wait-Job
Receive-Job -Name PJob -Verbose
Remove-Job -Name PJob -ErrorAction SilentlyContinue -ErrorVariable err
Remove-Item -Path "$env:TEM开发者_如何学编程P\ScriptBlock.ps1"


I believe this might be what you are looking for: A self elevating PowerShell script

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜