Core/Confirm-WDACConfig.psm1
Function Confirm-WDACConfig { [CmdletBinding(DefaultParameterSetName = 'List Active Policies')] Param( [Alias('L')] [Parameter(Mandatory = $false, ParameterSetName = 'List Active Policies')][System.Management.Automation.SwitchParameter]$ListActivePolicies, [Alias('V')] [Parameter(Mandatory = $false, ParameterSetName = 'Verify WDAC Status')][System.Management.Automation.SwitchParameter]$VerifyWDACStatus, [Alias('S')] [Parameter(Mandatory = $false, ParameterSetName = 'Check SmartAppControl Status')][System.Management.Automation.SwitchParameter]$CheckSmartAppControlStatus ) DynamicParam { # Add the dynamic parameters to the param dictionary $ParamDictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new() if ($PSBoundParameters['ListActivePolicies']) { # Create a dynamic parameter for -OnlyBasePolicies $OnlyBasePoliciesDynamicParameter = [System.Management.Automation.ParameterAttribute]@{ Mandatory = $false ParameterSetName = 'List Active Policies' HelpMessage = 'Only List Base Policies' } $ParamDictionary.Add('OnlyBasePolicies', [System.Management.Automation.RuntimeDefinedParameter]::new( 'OnlyBasePolicies', [System.Management.Automation.SwitchParameter], [System.Management.Automation.ParameterAttribute[]]@($OnlyBasePoliciesDynamicParameter) )) # Create a dynamic parameter for -OnlySupplementalPolicies $OnlySupplementalPoliciesDynamicParameter = [System.Management.Automation.ParameterAttribute]@{ Mandatory = $false ParameterSetName = 'List Active Policies' HelpMessage = 'Only List Supplemental Policies' } $ParamDictionary.Add('OnlySupplementalPolicies', [System.Management.Automation.RuntimeDefinedParameter]::new( 'OnlySupplementalPolicies', [System.Management.Automation.SwitchParameter], [System.Management.Automation.ParameterAttribute[]]@($OnlySupplementalPoliciesDynamicParameter) )) } # Create a dynamic parameter for -SkipVersionCheck, Adding this parameter as dynamic will make it appear at the end of the parameters $SkipVersionCheckDynamicParameter = [System.Management.Automation.ParameterAttribute]@{ Mandatory = $false # To make this parameter available for all parameter sets ParameterSetName = '__AllParameterSets' HelpMessage = 'Skip Version Check' } $ParamDictionary.Add('SkipVersionCheck', [System.Management.Automation.RuntimeDefinedParameter]::new( 'SkipVersionCheck', [System.Management.Automation.SwitchParameter], [System.Management.Automation.ParameterAttribute[]]@($SkipVersionCheckDynamicParameter) )) return $ParamDictionary } begin { # Detecting if Verbose switch is used $PSBoundParameters.Verbose.IsPresent ? ([System.Boolean]$Verbose = $true) : ([System.Boolean]$Verbose = $false) | Out-Null # Importing the $PSDefaultParameterValues to the current session, prior to everything else . "$ModuleRootPath\CoreExt\PSDefaultParameterValues.ps1" # Importing the required sub-modules Write-Verbose -Message 'Importing the required sub-modules' Import-Module -FullyQualifiedName "$ModuleRootPath\Shared\Update-self.psm1" -Force Import-Module -FullyQualifiedName "$ModuleRootPath\Shared\Write-ColorfulText.psm1" -Force # Regular parameters are automatically bound to variables in the function scope # Dynamic parameters however, are only available in the parameter dictionary, which is why we have to access them using $PSBoundParameters # or assign them manually to another variable in the function's scope [System.Management.Automation.SwitchParameter]$OnlyBasePolicies = $($PSBoundParameters['OnlyBasePolicies']) [System.Management.Automation.SwitchParameter]$OnlySupplementalPolicies = $($PSBoundParameters['OnlySupplementalPolicies']) [System.Management.Automation.SwitchParameter]$SkipVersionCheck = $($PSBoundParameters['SkipVersionCheck']) # if -SkipVersionCheck wasn't passed, run the updater if (-NOT $SkipVersionCheck) { Update-self -InvocationStatement $MyInvocation.Statement } # Script block to show only non-system Base policies [System.Management.Automation.ScriptBlock]$OnlyBasePoliciesBLOCK = { [System.Object[]]$BasePolicies = (&'C:\Windows\System32\CiTool.exe' -lp -json | ConvertFrom-Json).Policies | Where-Object -FilterScript { ($_.IsSystemPolicy -ne 'True') -and ($_.PolicyID -eq $_.BasePolicyID) } Write-ColorfulText -Color Lavender -InputText "`nThere are currently $(($BasePolicies.count)) Non-system Base policies deployed" $BasePolicies } # Script block to show only non-system Supplemental policies [System.Management.Automation.ScriptBlock]$OnlySupplementalPoliciesBLOCK = { [System.Object[]]$SupplementalPolicies = (&'C:\Windows\System32\CiTool.exe' -lp -json | ConvertFrom-Json).Policies | Where-Object -FilterScript { ($_.IsSystemPolicy -ne 'True') -and ($_.PolicyID -ne $_.BasePolicyID) } Write-ColorfulText -Color Lavender -InputText "`nThere are currently $(($SupplementalPolicies.count)) Non-system Supplemental policies deployed`n" $SupplementalPolicies } # If no main parameter was passed, run all of them if (!$ListActivePolicies -and !$VerifyWDACStatus -and !$CheckSmartAppControlStatus) { $ListActivePolicies = $true $VerifyWDACStatus = $true $CheckSmartAppControlStatus = $true } } process { if ($ListActivePolicies) { if ($OnlyBasePolicies) { &$OnlyBasePoliciesBLOCK } if ($OnlySupplementalPolicies) { &$OnlySupplementalPoliciesBLOCK } if (!$OnlyBasePolicies -and !$OnlySupplementalPolicies) { &$OnlyBasePoliciesBLOCK; &$OnlySupplementalPoliciesBLOCK } } if ($VerifyWDACStatus) { Write-Verbose -Message 'Checking the status of WDAC using Get-CimInstance' Get-CimInstance -ClassName Win32_DeviceGuard -Namespace root\Microsoft\Windows\DeviceGuard | Select-Object -Property *codeintegrity* | Format-List Write-ColorfulText -Color Lavender -InputText "2 -> Enforced`n1 -> Audit mode`n0 -> Disabled/Not running`n" } if ($CheckSmartAppControlStatus) { Write-Verbose -Message 'Checking the status of Smart App Control using Get-MpComputerStatus' Get-MpComputerStatus | Select-Object -Property SmartAppControlExpiration, SmartAppControlState if ((Get-MpComputerStatus).SmartAppControlState -eq 'Eval') { Write-ColorfulText -Color Pink -InputText "`nSmart App Control is in Evaluation mode." } elseif ((Get-MpComputerStatus).SmartAppControlState -eq 'On') { Write-ColorfulText -Color Pink -InputText "`nSmart App Control is turned on." } elseif ((Get-MpComputerStatus).SmartAppControlState -eq 'Off') { Write-ColorfulText -Color Pink -InputText "`nSmart App Control is turned off." } } } <# .SYNOPSIS Shows the status of WDAC on the system, lists the currently deployed policies and shows the details about each of them. It can also show the status of Smart App Control. .LINK https://github.com/HotCakeX/Harden-Windows-Security/wiki/Confirm-WDACConfig .DESCRIPTION Using official Microsoft methods, Show the status of WDAC (Windows Defender Application Control) on the system, list the current deployed policies and show details about each of them. .COMPONENT Windows Defender Application Control, ConfigCI PowerShell module .FUNCTIONALITY Using official Microsoft methods, Show the status of WDAC (Windows Defender Application Control) on the system, list the current deployed policies and show details about each of them. .PARAMETER ListActivePolicies Lists the currently deployed policies and shows details about each of them .PARAMETER VerifyWDACStatus Shows the status of WDAC (Windows Defender Application Control) on the system .PARAMETER CheckSmartAppControlStatus Checks the status of Smart App Control and reports the results on the console .PARAMETER SkipVersionCheck Can be used with any parameter to bypass the online version check - only to be used in rare cases .EXAMPLE Confirm-WDACConfig -ListActivePolicies -OnlyBasePolicies .EXAMPLE Confirm-WDACConfig -ListActivePolicies -OnlySupplementalPolicies .EXAMPLE Confirm-WDACConfig -ListActivePolicies .INPUTS System.Management.Automation.SwitchParameter .OUTPUTS System.String System.Object #> } # SIG # Begin signature block # MIILkgYJKoZIhvcNAQcCoIILgzCCC38CAQExDzANBglghkgBZQMEAgEFADB5Bgor # BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG # KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCDR/iu8QxMaG3v7 # ZZuvA2wq/cZIFOR9pMrNpebuU4eNNqCCB9AwggfMMIIFtKADAgECAhMeAAAABI80 # LDQz/68TAAAAAAAEMA0GCSqGSIb3DQEBDQUAME8xEzARBgoJkiaJk/IsZAEZFgNj # b20xIjAgBgoJkiaJk/IsZAEZFhJIT1RDQUtFWC1DQS1Eb21haW4xFDASBgNVBAMT # C0hPVENBS0VYLUNBMCAXDTIzMTIyNzExMjkyOVoYDzIyMDgxMTEyMTEyOTI5WjB5 # MQswCQYDVQQGEwJVSzEeMBwGA1UEAxMVSG90Q2FrZVggQ29kZSBTaWduaW5nMSMw # IQYJKoZIhvcNAQkBFhRob3RjYWtleEBvdXRsb29rLmNvbTElMCMGCSqGSIb3DQEJ # ARYWU3B5bmV0Z2lybEBvdXRsb29rLmNvbTCCAiIwDQYJ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9iG4D6Ul3LpAiSxgker14LtoUMYYUQuPM0 # cqqBCDIF4ECicoAuNFXrvbgyLD/eRmRn32iLpk2l0lH5ystmuN392Q5NA5+sZGza # yt96bZvVG5OqastggmZTB8lyxM+eIAwMu4qW4nMdC/syInq7/JggU2UrNJz066EX # zlWxGT3VGyYtQH5wwPzyCoNeSGtpxZI5IjYkN0GotxbFDlclnvY= # SIG # End signature block |