Up 0 Down 0

Suppress Network Shares Error

Detection:

$regKeyPath = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider"
$expectedValue = 0
if (Test-Path $regKeyPath) {
    $currentValue = (Get-ItemProperty -Path $regKeyPath -Name RestoreConnection).RestoreConnection
    if ($currentValue -eq $expectedValue) {
        Write-Output "Compliant: RestoreConnection registry value is set to $expectedValue"
        exit 0
    } else {
        Write-Output "Non-compliant: RestoreConnection registry value is not set to $expectedValue"
        exit 1
    }
} else {
    Write-Output "Non-compliant: RestoreConnection registry key does not exist"
    exit 1
}

Remediation:

$regKeyPath = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\NetworkProvider"
$valueToSet = 0
Set-ItemProperty -Path $regKeyPath -Name "RestoreConnection" -Value $valueToSet

# Check if the registry value was set successfully
if ($?) {
    Write-Output "Remediated: RestoreConnection registry value set to $valueToSet"
    exit 0
} else {
    Write-Output "Failed to remediate: Unable to set RestoreConnection registry value"
    exit 1
}