I am currently logged into my system as administrator, and run power1.ps1 code to call another power2.ps1 script in elevated mode.
$command = "C:\script\Power2.ps1"
Invoke-Expression $command
power2.ps1
includes the block to run the script with admin privileges, but my problem is I that I get a UAC pop-up dialog asking for confirmation where I have to click on Yes.
Code in Power2.ps1
If (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))
{
$arguments = "& '" + $myinvocation.mycommand.definition + "'"
Start-Process powershell -Verb runAs -ArgumentList $arguments
Break
}
Write-Host "Admin Privilege Code Here"
Is there any way I can completely automate the process? I will not be able to change the UAC access to disable.