cEPRSDisableUAC.psm1

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<#
This resource manages adding users to the GROUP.
[DscResource()] indicates the class is a DSC resource
#>

[DSCResource()]
class cEPRSDisableUAC
{


    [DscProperty(Key)] [validateset("true","false")] [string] $EnableLUA
    

[cEPRSDisableUAC] Get()
{

    $CurrentState=(Get-ItemProperty HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System).EnableLUA

    if(($CurrentState -eq "0") -and ($this.EnableLUA -eq $false))
   {
        $this.EnableLUA = $false
   }
    else
   {
        $this.EnableLUA = $true
   }
        return $this

   }

[void] Set()

{
    Write-Verbose( "GPO Settings started for x86 bit server-Set $($this.EnableLUA)") -Verbose
    if ($this.EnableLUA -eq $false)
    {
        Write-Verbose( "GPO Settings started for x86 bit server-Set $this.EnableLUA") -Verbose
           
        & "$env:SystemRoot\System32\reg.exe" ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 4 /f
        & "$env:SystemRoot\System32\reg.exe" ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableInstallerDetection /t REG_DWORD /d 1 /f
        & "$env:SystemRoot\System32\reg.exe" ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t REG_DWORD /d 0 /f
        gpupdate
    }
    else
    {
        Write-Verbose( "GPO Settings started for x86 bit server-Set $this.EnableLUA") -Verbose
        & "$env:SystemRoot\System32\reg.exe" ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 4 /f
        & "$env:SystemRoot\System32\reg.exe" ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableInstallerDetection /t REG_DWORD /d 1 /f
        & "$env:SystemRoot\System32\reg.exe" ADD "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA /t REG_DWORD /d 1 /f
        gpupdate
    }
}

[bool] Test()
{
        Write-Verbose "In Test" -Verbose

        $CurrentState=(Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System").EnableLUA

        Write-Verbose "CurrentState: $CurrentState" -Verbose

       if(($CurrentState -eq "0") -and ($this.EnableLUA -eq $false))
       {
            return $true
       }
       elseif(($CurrentState -eq "1") -and ($this.EnableLUA -eq $true))
       {
            return $true
       }
       else
       {
            return $false
       }
  }

  }