1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
function Set-UAC { <# .SYNOPSIS Enables or disables User Account Control (UAC) on a computer, locally or remote. .DESCRIPTION Enables or disables User Account Control (UAC) on a computer, locally or remote. .AUTHOR Jeff Wouters .NOTES PowerShell 2.0 or higher is required for proper execution of this script. .EXAMPLE Set-UAC -Enabled .EXAMPLE Set-UAC -Disabled -Restart .EXAMPLE Set-UAC -ComputerName [ComputerName] -Enabled -Restart .EXAMPLE Set-UAC -ComputerName [ComputerName] -Disabled .INPUTS N/A. #> [cmdletBinding(SupportsShouldProcess = $True)] param( [parameter(ValueFromPipeline = $False, ValueFromPipelineByPropertyName = $True, Mandatory = $False)][Alias("Computer")] [string]$ComputerName = $env:ComputerName, [parameter(ValueFromPipeline = $False, ValueFromPipelineByPropertyName = $True, Mandatory = $False)][switch]$Enable, [parameter(ValueFromPipeline = $False, ValueFromPipelineByPropertyName = $True, Mandatory = $False)][switch]$Disable, [parameter(ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $true, Mandatory = $false)][switch]$Restart ) [string]$RegPath = "Software\Microsoft\Windows\CurrentVersion\Policies\System" [string]$RegValue = "EnableLUA" $AccessReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$ComputerName) $Subkey = $AccessReg.OpenSubKey($RegPath,$True) $Subkey.ToString() | Out-Null if (!($Enable) -and !($Disable)){ $UACMessage = "Please use either the -Enable or -Disable parameter to change the status of UAC." } elseif ($Enable) { $Subkey.SetValue($RegValue, 1) } elseif ($Disable) { $Subkey.SetValue($RegValue, 0) } if ($Restart) { Restart-Computer $ComputerName -Force $RestartMessage = "$ComputerName will now perform a in order for the UAC configuration change to take affect." } else { $RestartMessage = "Please restart $ComputerName in order for the UAC configuration change to take affect." } return $UACMessage return $RestartMessage } |
October 12, 2012
Hi Jeff,
Where we can add the remote computer Name
thx
Hi Rohan,
You can use the -ComputerName parameter for that. It automatically connects to the remote computer when you use the -ComputerName parameter with the name of the remote computer.
Jeff.
Thanks this is very helpful, I am trying to do almost the same thing but I would like to enable UAC depending on the user account that logs in.