Last active
June 20, 2025 09:26
-
-
Save win2000b/39b6900aebc6ab1012576c68420e47cb to your computer and use it in GitHub Desktop.
Intune Device Detect and Remediate - Registry Key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <# | |
| Type: Detection | |
| Job: Detects Registry Key and if present or not | |
| Run as: System | |
| Context: 64 Bit | |
| #> | |
| # Define Varibles | |
| $regPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client" | |
| $regName = "AllowBasic" | |
| $desiredValue = 0 | |
| # Check if the registry key exists and is set correctly | |
| $currentValue = Get-ItemProperty -Path $regPath -Name $regName -ErrorAction SilentlyContinue | |
| if ($null -eq $currentValue) { | |
| Write-Output "Registry key does not exist." | |
| exit 1 | |
| } elseif ($currentValue.$regName -ne $desiredValue) { | |
| Write-Output "Registry key is not set correctly." | |
| exit 1 | |
| } else { | |
| Write-Output "Registry key is set correctly." | |
| exit 0 | |
| } | |
| <# | |
| Type: Remediation | |
| Job: Remediates Registry Key if not present | |
| Run as: System | |
| Context: 64 Bit | |
| #> | |
| # Define Varibles | |
| $regPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WinRM\Client" | |
| $regName = "AllowBasic" | |
| $desiredValue = 0 | |
| # Check if the registry path exists | |
| if (-not (Test-Path $regPath)) { | |
| New-Item -Path $regPath -Force | Out-Null | |
| } | |
| # Check if the value exists and is set correctly | |
| $currentValue = Get-ItemProperty -Path $regPath -Name $regName -ErrorAction SilentlyContinue | |
| if ($null -eq $currentValue -or $currentValue.$regName -ne $desiredValue) { | |
| New-ItemProperty -Path $regPath -Name $regName -Value $desiredValue -PropertyType DWORD -Force | Out-Null | |
| Write-Output "Registry key updated: $regName set to $desiredValue" | |
| } else { | |
| Write-Output "Registry key already set correctly." | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment