0

adminロールを持つユーザーを使用しています。ただし、デフォルトでは、スクリプトは管理者としてではなくUACモードで実行されます。 UACダイアログボックスを使わずにpowershellスクリプトでpowershellコンソールを開くことは可能ですか?PowershellがPowerShellコンソールをUACダイアログボックスなしで管理者モードで開き、何らかのタスクを実行する

私は次のようにやってみたいけど、それは私に出席する必要があります]ダイアログボックスを与えるタスク上昇しようとした:しかし、これは私がしたい場合は確認してUACのダイアログボックスが開きます

# Get the ID and security principal of the current user account 
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent(); 
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID); 

# Get the security principal for the administrator role 
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator; 

# Check to see if we are currently running as an administrator 
if ($myWindowsPrincipal.IsInRole($adminRole)) 
{ 
    # We are running as an administrator, so change the title and background colour to indicate this 
    $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"; 
    $Host.UI.RawUI.BackgroundColor = "DarkBlue"; 
    Clear-Host; 
} 
else { 
    # We are not running as an administrator, so relaunch as administrator 

    # Create a new process object that starts PowerShell 
    $newProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell"; 


    # Indicate that the process should be elevated 
    $newProcess.Verb = "runas"; 

    # Start the new process 
    [System.Diagnostics.Process]::Start($newProcess); 

    # Exit from the current, unelevated, process 
    Exit; 
} 

#DOING SOME TASK HERE 

を管理者モードでPowerShellを開きます。

私が試したもう一つの方法は、デフォルトで管理者モードでPowerShellコンソールを開くことです(私はWS 2012を使用し、これを行う方法はWindows 10と同じです)。しかし、私はDevOpsが私にそうしないようにシステムにこのような変更を加える権利を持っていません。これに対処するためにPowerShellスクリプトを使って他の方法がありますか?

+0

何が投票されますか?私は、有権者が同じ理由を提供するよう、有権者に要求する。 – Rishi

+0

私は時間の短い量で昨日のdownvotesのいくつかを得た - その男が持っていたか、誰かがハックした問題を知らない – DAXaholic

答えて

0

回避策として、「スケジュールされた」タスクを作成することができます。これは昇格した状態で実行し、そのタスクを最初のPowerShellから起動するように設定されています。

このようなタスクの設定方法についてはhere、それをトリガーする方法についてはhereを参照してください。

+1

あなたの答えのための@DAXaholicありがとうございます。しかし、それを追加する機会はありませんでしたが、私はそれを整理しました。そして、オートメーションチームはあなたと同じことを提案しました。 – Rishi

+0

Btws、@ DAXaholic、私はこれを行う必要があります:http://stackoverflow.com/questions/39108473/unable-to-disable-the-microsoft-office-customization-installer-while-automating。私はタスクスケジューラを初めて使い慣れているので、私が求めていることをどのように達成できるかについて私に先導を与えることができますか?私は、タスクスケジューラ自体とのやり取りが必要だと感じています... – Rishi

関連する問題