Skip to content

Instantly share code, notes, and snippets.

@naamancampbell
Created October 21, 2017 11:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naamancampbell/1aa3338c316b4543115e68e5fc633f8f to your computer and use it in GitHub Desktop.
Save naamancampbell/1aa3338c316b4543115e68e5fc633f8f to your computer and use it in GitHub Desktop.
Disables UAC without privilege escalation. NB. Must run from another host (mgmt).
##########
## 1. Save file on mgmt host.
## - change 'COMPUTERNAME' to target hostname
##########
Configuration Disable-UAC {
Import-DscResource -ModuleName PsDesiredStateConfiguration
Import-DscResource -ModuleName xSystemSecurity -Name xUac
Node 'COMPUTERNAME' {
xUAC NeverNotifyAndDisableAll {
Setting = "NeverNotifyAndDisableAll"
}
}
}
Disable-UAC
##########
## 2. Run the following commands on remote host.
## - change 'COMPUTERNAME' to target hostname
## - Use `$AdminCred = Get-Credential` as an alternative to .\CloudFormation-PowerShell-Creds.ps1
##
## *** WARNING *** - this script will reboot the target host without prompting
##
##########
$TargetHost = "COMPUTERNAME"
Set-PSRepository -InstallationPolicy Trusted -Name "PSGallery"
Install-Module xSystemSecurity -Scope CurrentUser
$AdminCred = .\CloudFormation-PowerShell-Creds.ps1 -AccessCredential Admin -CredentialPath C:\Admin\Keys\CF-Creds-20171018T0954207027
$CIMSession = New-CimSession -ComputerName $TargetHost -Credential $AdminCred
Start-DscConfiguration -Path "C:\Users\Admin\Desktop\Disable-UAC" -CimSession $CIMSession -Wait -Verbose
Restart-Computer $TargetHost -Credential $AdminCred -Protocol WSMan -Force
$UAC = Get-ItemProperty -Path "registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\policies\system" -Name EnableLUA
$UAC.EnableLUA
Start-Process -FilePath powershell.exe -verb RunAs -WorkingDirectory C:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment