Toggle SmartScreen Settings

You may have noticed that the Action Center on Windows Server 2012 is prompting to turn on the SmartScreen feature

It can be set with the SmartScreenSettings.exe executable in GUI mode:

…and the following small piece of code allows to either query or set its status under Powershell:

# Requires -Version 3.0            
            
Function Get-SmartScreenSettingsStatus {            
[CmdletBinding()]            
Param()            
Begin {}            
Process {            
    try {            
       $val = Get-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name SmartScreenEnabled -ErrorAction Stop            
    } catch {            
                    
    }            
    if ($val) {            
        'Smart screen settings is set to: {0}' -f $val.SmartScreenEnabled            
    } else {            
        'Smart screen settings is set to: Off (by default)'            
    }            
}            
End {}            
}            
            
Function Set-SmartScreenSettingsStatus {            
[CmdletBinding()]            
Param(            
    [Parameter(Mandatory)]            
    [ValidateSet("Off","Prompt","RequireAdmin")]                        
    [system.String]$State            
)            
Begin {            
    # Make sure we run as admin                        
    $usercontext = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()                        
    $IsAdmin = $usercontext.IsInRole(544)                                                                   
    if (-not($IsAdmin)) {                        
        Write-Warning "Must run powerShell as Administrator to perform these actions"                        
        break            
    }                         
            
}            
Process {            
    try {            
        Set-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer -Name SmartScreenEnabled -ErrorAction Stop -Value $State -Force             
    } catch {            
        Write-Warning -Message "Failed to write registry value because $($_.Exception.Message)"            
    }            
}            
End {}            
}

Advertisements

2 thoughts on “Toggle SmartScreen Settings

  1. What’s the point of this code without computername parameter? It’s so much easier and faster to just use the GUI.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s