Advertisement
BaSs_HaXoR

WIN 10 Set-Privacy Script (powershell)

Jun 21st, 2018
524
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # https://github.com/hahndorf/Set-Privacy
  2. # WIN 10 Set-Privacy POWERSHELL SCRIPT
  3.  
  4. <#PSScriptInfo
  5.  
  6. .VERSION 1.1703.1
  7.  
  8. .GUID bd3a1ade-420c-4ac6-8558-b4f8df963aff
  9.  
  10. .AUTHOR Peter Hahndorf
  11.  
  12. .COMPANYNAME
  13.  
  14. .COPYRIGHT
  15.  
  16. .TAGS
  17.  
  18. .LICENSEURI https://raw.githubusercontent.com/hahndorf/Set-Privacy/master/LICENSE
  19.  
  20. .PROJECTURI https://github.com/hahndorf/Set-Privacy
  21.  
  22. .ICONURI https://raw.githubusercontent.com/hahndorf/Set-Privacy/master/set-privacy.png
  23.  
  24. .EXTERNALMODULEDEPENDENCIES
  25.  
  26. .REQUIREDSCRIPTS
  27.  
  28. .EXTERNALSCRIPTDEPENDENCIES
  29.  
  30. .RELEASENOTES
  31.    1.0.1 - 10-Aug-2016 Fixed a bug on Version 1607 with handling registry paths
  32.    1.1.0 - 13-Apr-2017 Added setting introducted by the Creator's Update (Vs.1703)
  33.                        Fixed a bug enabling named features.
  34.    1.1703.0 - 14-April-2017 Changed version number to reflect matching Windows
  35.                             version and added more details to the readme file.
  36.                             Removed SpyNet feature.
  37.    1.1703.1 - 15-April-2017 Updated Icon and iconUri
  38.  
  39. #>
  40.  
  41. <#
  42. .SYNOPSIS
  43.     PowerShell script to batch-change privacy settings in Windows 10 and Server 2016+
  44. .DESCRIPTION
  45.     With so many different privacy settings in Windows 10, it makes sense to have a script to change them.
  46. .PARAMETER Strong
  47.     Makes changes to allow for the highest privacy
  48. .PARAMETER Default
  49.     Reverts to Windows defaults
  50. .PARAMETER Balanced
  51.     Turns off most things but not everything.
  52. .PARAMETER Admin
  53.     Updates machine settings rather than user settings, still requires Strong,Balanced or Default switches. Needs to run as elevated admin.
  54.     If this switch is selected, no user settings are changed.
  55. .PARAMETER Features
  56.     A comma separated list of features to disable or enable. Use the Tab key to show all allowed values
  57. .PARAMETER Disable
  58.     Use with -Features to disable all those features
  59. .PARAMETER Enable
  60.     Use with -Features to enable all those features
  61.  
  62. .EXAMPLE      
  63.     Set-Privacy -Strong
  64.     Sets strong privacy settings for the current user
  65. .EXAMPLE      
  66.     Set-Privacy -Balanced
  67.     Runs the script to set the balanced privacy settings  
  68. .EXAMPLE      
  69.     Set-Privacy -Strong -Admin
  70.     Runs the script to set the strong settings on the machine level. This covers Windows update and WiFi sense.  
  71. .EXAMPLE      
  72.     Set-Privacy -disable -Features WifiSense,ShareUpdates,Contacts
  73.     Disabled those three features to improve your privacy  
  74. .NOTES
  75.     Requires Windows 10 or higher
  76.     Author:  Peter Hahndorf
  77.     Created: August 4th, 2015
  78.    
  79. .LINK
  80.     https://github.com/hahndorf/Set-Privacy  
  81. #>
  82.  
  83. param(
  84.     [parameter(Mandatory=$true,ParameterSetName = "Strong")]
  85.     [switch]$Strong,
  86.     [parameter(Mandatory=$true,ParameterSetName = "Default")]
  87.     [switch]$Default,
  88.     [parameter(Mandatory=$true,ParameterSetName = "Balanced")]
  89.     [switch]$Balanced,
  90.     [parameter(ParameterSetName = "Balanced")]
  91.     [parameter(ParameterSetName = "Default")]
  92.     [parameter(ParameterSetName = "Strong")]
  93.     [switch]$Admin,
  94.     [parameter(Mandatory=$true,ParameterSetName = "Disable")]
  95.     [switch]$Disable,
  96.     [parameter(Mandatory=$true,ParameterSetName = "Enable")]
  97.     [switch]$Enable,
  98.     [parameter(Mandatory=$true,ParameterSetName = "Enable")]
  99.     [parameter(Mandatory=$true,ParameterSetName = "Disable")]
  100.     [ValidateSet("AdvertisingId","ImproveTyping","Location","Camera","Microphone","SpeachInkingTyping",`
  101.     "AccountInfo","Contacts","Calendar","Messaging","Radios","OtherDevices","FeedbackFrequency","ShareUpdates",`
  102.     "WifiSense","Telemetry","SpyNet","DoNotTrack","SearchSuggestions","PagePrediction","PhishingFilter",`
  103.     "StartTrackProgs","AppNotifications","CallHistory","Email","Tasks","AppDiagnostics","TailoredExperiences")]
  104.     [string[]]$Feature
  105. )          
  106.  
  107. Begin
  108. {
  109.  
  110. #requires -version 3
  111.  
  112. # check https://fix10.isleaked.com/ for changing things manually.
  113.  
  114.     # ----------- Helper Functions -----------
  115.  
  116.     Function Test-Admin()
  117.     {
  118.         if (!($userIsAdmin))
  119.         {
  120.             Write-Warning "When using -admin switch or specifying a machine setting, please run this script as elevated administrator"
  121.             Exit 102
  122.         }
  123.     }
  124.  
  125.     Function Test-RegistryValue([String]$Path,[String]$Name){
  126.  
  127.       if (!(Test-Path $Path)) { return $false }
  128.    
  129.       $Key = Get-Item -LiteralPath $Path
  130.       if ($Key.GetValue($Name, $null) -ne $null) {
  131.           return $true
  132.       } else {
  133.           return $false
  134.       }
  135.     }
  136.  
  137.     Function Get-RegistryValue([String]$Path,[String]$Name){
  138.  
  139.       if (!(Test-Path $Path)) { return $null }
  140.    
  141.       $Key = Get-Item -LiteralPath $Path
  142.       if ($Key.GetValue($Name, $null) -ne $null) {
  143.           return $Key.GetValue($Name, $null)
  144.       } else {
  145.           return $null
  146.       }
  147.     }
  148.  
  149.     Function Remove-RegistryValue([String]$Path,[String]$Name){
  150.  
  151.         $old = Get-RegistryValue -Path $Path -Name $Name
  152.         if ($old -ne $null)
  153.         {
  154.             Remove-ItemProperty -Path "$Path" -Name "$Name"
  155.             Write-Host "$Path\$Name removed" -ForegroundColor Yellow
  156.         }
  157.         else
  158.         {
  159.             Write-Host "$Path\$Name does not exist" -ForegroundColor Green
  160.         }
  161.  
  162.     }
  163.  
  164.     Function Create-RegistryKey([string]$path)
  165.     {        
  166.         # creates a parent key and if needed grandparent key as well
  167.         # for this script that is good enough
  168.  
  169.         If (!(Test-Path $Path))
  170.         {
  171.             $parent = "$path\.."
  172.  
  173.             $grandParent = "$parent\.."
  174.             If (!(Test-Path $grandParent))
  175.             {
  176.                 New-item -Path $grandParent | Out-Null
  177.             }
  178.  
  179.             If (!(Test-Path $parent))
  180.             {
  181.                 New-item -Path $parent | Out-Null
  182.             }
  183.  
  184.             New-item -Path $Path | Out-Null
  185.         }
  186.     }
  187.  
  188.     Function Add-RegistryDWord([String]$Path,[String]$Name,[int32]$value){
  189.  
  190.         $old = Get-RegistryValue -Path $Path -Name $Name
  191.         if ($old -ne $null)
  192.         {
  193.             if ([int32]$old -eq $value)
  194.             {
  195.                 Write-Host "$Path\$Name already set to $value" -ForegroundColor Green
  196.                 return
  197.             }
  198.         }
  199.  
  200.  
  201.         If (Test-RegistryValue $Path $Name)
  202.         {
  203.             Set-ItemProperty -Path $Path -Name $Name -Value $value
  204.         }
  205.         else
  206.         {
  207.             Create-RegistryKey -path $path
  208.             New-ItemProperty -Path $Path -Name $Name -PropertyType DWord -Value $value | Out-Null
  209.         }
  210.  
  211.  
  212.         Write-Host "$Path\$Name changed to $value" -ForegroundColor Yellow
  213.     }
  214.  
  215.     Function Add-RegistryString([String]$Path,[String]$Name,[string]$value){
  216.  
  217.  
  218.         $old = Get-RegistryValue -Path $Path -Name $Name
  219.         if ($old -ne $null)
  220.         {
  221.             if ([string]$old -eq $value)
  222.             {
  223.                 Write-Host "$Path\$Name already set to $value" -ForegroundColor Green
  224.                 return
  225.             }
  226.         }
  227.  
  228.         If (Test-RegistryValue $Path $Name)
  229.         {
  230.             Set-ItemProperty -Path $Path -Name $Name -Value $value
  231.         }
  232.         else
  233.         {
  234.             Create-RegistryKey -path $path
  235.             New-ItemProperty -Path $Path -Name $Name -PropertyType String -Value $value |Out-Null
  236.         }
  237.  
  238.         Write-Host "$Path\$Name changed to $value" -ForegroundColor Yellow
  239.     }
  240.  
  241.     Function Get-AppSID(){
  242.  
  243.         Get-ChildItem "HKCU:\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Mappings" | foreach {
  244.  
  245.         $key = $_.Name -replace "HKEY_CURRENT_USER","HKCU:"
  246.  
  247.         $val = Get-RegistryValue -Path $key -Name "Moniker"
  248.  
  249.         if ($val -ne $null)
  250.         {
  251.             if ($val -match "^microsoft\.people_")
  252.             {
  253.                 $script:sidPeople = $_.PsChildName
  254.             }
  255.             if ($val -match "^microsoft\.windows\.cortana")
  256.             {
  257.                 $script:sidCortana = $_.PsChildName
  258.             }
  259.         }    
  260.     }              
  261.     }
  262.  
  263.     Function DeviceAccess([string]$guid,[string]$value){
  264.         Add-RegistryString -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeviceAccess\Global\{$guid}" -Name Value -Value $value
  265.     }
  266.  
  267.     Function DeviceAccessName([string]$name,[string]$value){
  268.         Add-RegistryString -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeviceAccess\Global\$name" -Name Value -Value $value
  269.     }
  270.  
  271.     Function DeviceAccessApp([string]$app,[string]$guid,[string]$value){
  272.  
  273.         Add-RegistryString -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeviceAccess\$app\{$guid}" -Name Value -Value $value
  274.     }
  275.  
  276.     Function Report(){
  277.  
  278.         Write-Host "Privacy settings changed"
  279.         Exit 0
  280.     }
  281.  
  282.     # ----------- User Privacy Functions -----------
  283.    
  284.     Function SmartScreen([int]$value){
  285.        
  286.         # Turn on SmartScreen Filter
  287.         Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppHost" -Name EnableWebContentEvaluation -Value $value
  288.     }
  289.  
  290.     Function ImproveTyping([int]$value){
  291.  
  292.         # Send Microsoft info about how to write to help us improve typing and writing in the future
  293.         Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\Input\TIPC" -Name Enabled -Value $value
  294.     }
  295.  
  296.     Function AdvertisingId([int]$value){
  297.  
  298.        # Let apps use my advertising ID for experience across apps
  299.         Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\AdvertisingInfo" -Name Enabled -Value $value
  300.     }
  301.  
  302.     Function LanguageList([int]$value){
  303.  
  304.         # Let websites provice locally relevant content by accessing my language list
  305.         Add-RegistryDWord -Path "HKCU:\Control Panel\International\User Profile" -Name HttpAcceptLanguageOptOut -Value $value
  306.     }
  307.  
  308.     Function SpeachInkingTyping([bool]$enable){
  309.  
  310.         if ($enable)
  311.         {
  312.             Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\Personalization\Settings" -Name AcceptedPrivacyPolicy -Value 1
  313.             Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\InputPersonalization" -Name RestrictImplicitTextCollection -Value 0
  314.             Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\InputPersonalization" -Name RestrictImplicitInkCollection -Value 0
  315.             Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\InputPersonalization\TrainedDataStore" -Name HarvestContacts -Value 1
  316.         }
  317.         else
  318.         {
  319.             Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\Personalization\Settings" -Name AcceptedPrivacyPolicy -Value 0
  320.             Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\InputPersonalization" -Name RestrictImplicitTextCollection -Value 1
  321.             Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\InputPersonalization" -Name RestrictImplicitInkCollection -Value 1
  322.             Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\InputPersonalization\TrainedDataStore" -Name HarvestContacts -Value 0    
  323.         }
  324.     }
  325.  
  326.     Function Location([string]$value){
  327.  
  328.         DeviceAccess -guid "BFA794E4-F964-4FDB-90F6-51056BFE4B44" -value $value
  329.     }
  330.  
  331.     Function Camera([string]$value){
  332.  
  333.         DeviceAccess -guid "E5323777-F976-4f5b-9B55-B94699C46E44" -value $value
  334.     }
  335.  
  336.     Function Microphone([string]$value){
  337.         DeviceAccess -guid "2EEF81BE-33FA-4800-9670-1CD474972C3F" -value $value
  338.     }
  339.  
  340.     Function CallHistory([string]$value){
  341.         DeviceAccess -guid "8BC668CF-7728-45BD-93F8-CF2B3B41D7AB" -value $value
  342.     }
  343.  
  344.     Function Email([string]$value){
  345.         DeviceAccess -guid "9231CB4C-BF57-4AF3-8C55-FDA7BFCC04C5" -value $value
  346.     }
  347.  
  348.     Function Tasks([string]$value){
  349.         DeviceAccess -guid "E390DF20-07DF-446D-B962-F5C953062741" -value $value
  350.     }
  351.  
  352.     Function Contacts([string]$value){
  353.  
  354.         $exclude = $script:sidCortana + "|" + $script:sidPeople
  355.  
  356.         DeviceAccess -guid "7D7E8402-7C54-4821-A34E-AEEFD62DED93" -value $value
  357.  
  358.         Get-ChildItem HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeviceAccess | ForEach-Object{
  359.  
  360.             $app = $_.PSChildName
  361.  
  362.             if ($app -ne "Global")
  363.             {
  364.                 $key = $_.Name -replace "HKEY_CURRENT_USER","HKCU:"
  365.  
  366.                 $contactsGUID = "7D7E8402-7C54-4821-A34E-AEEFD62DED93"
  367.            
  368.                 $key += "\{$contactsGUID}"
  369.  
  370.                 if (Test-Path "$key")
  371.                 {
  372.                     if ($app -notmatch $exclude)
  373.                     {
  374.                         DeviceAccessApp -app $app -guid $contactsGUID -value $value
  375.                     }
  376.                 }
  377.             }
  378.         }
  379.     }
  380.  
  381.     Function Calendar([string]$value){
  382.         DeviceAccess -guid "D89823BA-7180-4B81-B50C-7E471E6121A3" -value $value
  383.     }
  384.  
  385.     Function AccountInfo([string]$value){
  386.         DeviceAccess -guid "C1D23ACC-752B-43E5-8448-8D0E519CD6D6" -value $value
  387.     }
  388.  
  389.     Function Messaging([string]$value){
  390.  
  391.         DeviceAccess -guid "992AFA70-6F47-4148-B3E9-3003349C1548" -value $value
  392.     }
  393.  
  394.     Function Radios([string]$value){
  395.  
  396.         DeviceAccess -guid "A8804298-2D5F-42E3-9531-9C8C39EB29CE" -value $value
  397.     }
  398.  
  399.     Function OtherDevices([string]$value){
  400.  
  401.         DeviceAccessName -name "LooselyCoupled" -value $value
  402.     }
  403.  
  404.     Function FeedbackFrequency([int]$value){
  405.  
  406.         if ($value -lt 0)
  407.         {
  408.             # remove entry
  409.             Remove-RegistryValue -Path "HKCU:\SOFTWARE\Microsoft\Siuf\Rules" -Name NumberOfSIUFInPeriod
  410.         }
  411.         else
  412.         {
  413.             Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\Siuf\Rules" -Name NumberOfSIUFInPeriod -Value $value
  414.         }
  415.     }
  416.  
  417.     Function AppNotifications([string]$value){
  418.         DeviceAccess -guid "52079E78-A92B-413F-B213-E8FE35712E72" -value $value
  419.     }    
  420.  
  421.     Function AppDiagnostics([string]$value){
  422.         DeviceAccess -guid "2297E4E2-5DBE-466D-A12B-0F8286F0D9CA" -value $value
  423.     }
  424.  
  425.     # ----------- Edge Browser Privacy Functions -----------
  426.  
  427.     [string]$EdgeKey = "HKCU:\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppContainer\Storage\microsoft.microsoftedge_8wekyb3d8bbwe\MicrosoftEdge"
  428.  
  429.     Function DoNotTrack([int]$value){
  430.  
  431.        # 1 adds the Do Not Track Header, 0 does not
  432.         Add-RegistryDWord -Path "$EdgeKey\Main" -Name DoNotTrack -Value $value
  433.     }
  434.  
  435.     Function SearchSuggestions([int]$value){
  436.    
  437.        # 0 disables search suggestions, 1 does not
  438.         Add-RegistryDWord -Path "$EdgeKey\User\Default\SearchScopes" -Name ShowSearchSuggestionsGlobal -Value $value
  439.     }
  440.  
  441.     Function PagePrediction([int]$value){
  442.    
  443.        # 0 disables PagePrediction, 1 enables them
  444.         Add-RegistryDWord -Path "$EdgeKey\FlipAhead" -Name FPEnabled -Value $value
  445.     }
  446.  
  447.     Function PhishingFilter([int]$value){
  448.    
  449.        # 0 disables PhishingFilter, 1 enables it
  450.         Add-RegistryDWord -Path "$EdgeKey\PhishingFilter" -Name EnabledV9 -Value $value
  451.     }
  452.  
  453.     Function StartTrackProgs([int]$value)
  454.     {
  455.         Add-RegistryDWord -Path "HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced" -Name Start_TrackProgs -Value $value
  456.     }
  457.  
  458.     Function TailoredExperiences([int]$value)
  459.     {
  460.         Add-RegistryDWord -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Privacy" -Name TailoredExperiencesWithDiagnosticDataEnabled -Value $value
  461.     }
  462.  
  463.     # ----------- Machine Settings Functions -----------
  464.  
  465.     Function ShareUpdates([int]$value){
  466.  
  467.         Test-Admin
  468.  
  469.         # 0 = Off
  470.         # 1 = PCs on my local network
  471.         # 3 = PCs on my local network, and PCs on the Internet
  472.  
  473.         Add-RegistryDWord -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\DeliveryOptimization\Config" -Name DODownloadMode -Value $value        
  474.     }
  475.  
  476.     Function WifiSense([int]$value){
  477.  
  478.         Test-Admin
  479.  
  480.         Add-RegistryDWord -Path "HKLM:\SOFTWARE\Microsoft\WcmSvc\wifinetworkmanager\features" -Name WiFiSenseCredShared -Value $value        
  481.         Add-RegistryDWord -Path "HKLM:\SOFTWARE\Microsoft\WcmSvc\wifinetworkmanager\features" -Name WiFiSenseOpen -Value $value        
  482.     }
  483.  
  484.     Function SpyNet([bool]$enable){
  485.  
  486.         # Access to these registry keys are not allowed for administrators
  487.         # so this does not work until we change those,
  488.         # we give admins full permissions and after updating the values change it back.
  489.  
  490.         Test-Admin
  491.  
  492. $definition = @"
  493. using System;
  494. using System.Runtime.InteropServices;
  495. namespace Win32Api
  496. {
  497.    public class NtDll
  498.    {
  499.        [DllImport("ntdll.dll", EntryPoint="RtlAdjustPrivilege")]
  500.        public static extern int RtlAdjustPrivilege(ulong Privilege, bool Enable, bool CurrentThread, ref bool Enabled);
  501.    }
  502. }
  503. "@
  504.                  
  505.         if (-not ("Win32Api.NtDll" -as [type]))
  506.         {
  507.             Add-Type -TypeDefinition $definition -PassThru | out-null
  508.         }
  509.         else
  510.         {
  511.              ("Win32Api.NtDll" -as [type]) | Out-Null
  512.         }
  513.        
  514.         $bEnabled = $false
  515.         # Enable SeTakeOwnershipPrivilege
  516.         $res = [Win32Api.NtDll]::RtlAdjustPrivilege(9, $true, $false, [ref]$bEnabled)
  517.  
  518.         $adminGroupSID = "S-1-5-32-544"
  519.  
  520.         $adminGroupName = (get-wmiobject -class "win32_account" -namespace "root\cimv2" | where-object{$_.sidtype -eq 4 -and $_.Sid -eq "$adminGroupSID"}).Name
  521.  
  522.         # we take ownership from SYSTEM and I tried to give it back but that failed. I don't think that's a problem.
  523.         $key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows Defender\Spynet", [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::takeownership)
  524.         $acl = $key.GetAccessControl()
  525.         $acl.SetOwner([System.Security.Principal.NTAccount]$adminGroupName)
  526.         $key.SetAccessControl($acl)
  527.  
  528.         $rule = New-Object System.Security.AccessControl.RegistryAccessRule ("$adminGroupName","FullControl","Allow")
  529.         $acl.SetAccessRule($rule)
  530.         $key.SetAccessControl($acl)
  531.  
  532.         if ($enable)
  533.         {
  534.     #        Add-RegistryDWord -Path "HKLM:\SOFTWARE\Microsoft\Windows Defender\Spynet" -Name "SpyNetReporting" -Value 2
  535.             Add-RegistryDWord -Path "HKLM:\SOFTWARE\Microsoft\Windows Defender\Spynet" -Name "SubmitSamplesConsent" -Value 1
  536.         }
  537.         else
  538.         {
  539.     #        Add-RegistryDWord -Path "HKLM:\SOFTWARE\Microsoft\Windows Defender\Spynet" -Name "SpyNetReporting" -Value 0    
  540.             Add-RegistryDWord -Path "HKLM:\SOFTWARE\Microsoft\Windows Defender\Spynet" -Name "SubmitSamplesConsent" -Value 0                  
  541.         }      
  542.  
  543.         # remove FUll Access ACE again
  544.         $acl.RemoveAccessRule($rule) | Out-Null
  545.         $key.SetAccessControl($acl)
  546.      
  547.     }
  548.  
  549.     Function Telemetry ([bool]$enable){
  550.  
  551.         Test-Admin
  552.  
  553.         # http://winaero.com/blog/how-to-disable-telemetry-and-data-collection-in-windows-10/
  554.         # this covers Diagnostic and usage data in 'Feedback and diagnostics'
  555.         if ($enable)
  556.         {
  557.             Set-service -Name DiagTrack -Status Running -StartupType Automatic
  558.             if ((Get-Service | where Name -eq dmwappushservice).count -eq 1)
  559.             {
  560.                 & sc.exe config dmwappushservice start= delayed-auto | Out-Null
  561.                 Set-service -Name dmwappushservice -Status Running
  562.             }
  563.             # just setting the value to zero did not do the trick.
  564.             Remove-RegistryValue -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name AllowTelemetry
  565.         }
  566.         else
  567.         {            
  568.             Stop-Service -Name DiagTrack -Force
  569.             Set-service -Name DiagTrack -StartupType Disabled
  570.            
  571.             if((Get-Service | where Name -eq dmwappushservice).count -eq 1)
  572.             {
  573.                 Stop-Service -Name dmwappushservice -Force
  574.                 Set-service -Name dmwappushservice -StartupType Disabled
  575.             }
  576.  
  577.             Add-RegistryDWord -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\DataCollection" -Name AllowTelemetry -Value 0
  578.                                            
  579.         }
  580.     }
  581.  
  582.     # ----------- Grouping Functions -----------
  583.  
  584.     Function Set-StrictPrivacyFeature([bool]$enable)
  585.     {
  586.         #enabled for -default, disabled for -strong and -balanced
  587.  
  588.         $AllowDeny = "Deny"
  589.         $OnOff = 0      
  590.         $OffOn = 1  
  591.        
  592.         if ($enable)
  593.         {
  594.             $AllowDeny = "Allow"
  595.             $OnOff = 1
  596.             $OffOn = 0
  597.         }
  598.  
  599.         # General
  600.         AdvertisingId -value $OnOff
  601.         ImproveTyping -value $OnOff          
  602.         # Location
  603.         Location -value $AllowDeny
  604.         # Camera
  605.         Camera -value $AllowDeny
  606.         # Microphone
  607.         Microphone -value $AllowDeny
  608.         # Speach, Inking, Typing
  609.         SpeachInkingTyping -enable $enable
  610.         # Account Info
  611.         AccountInfo -value $AllowDeny
  612.         # Contacts
  613.         Contacts -value $AllowDeny
  614.         # Calendar
  615.         Calendar -value $AllowDeny
  616.         # Messaging
  617.         Messaging -value $AllowDeny
  618.         # Radios
  619.         Radios -value $AllowDeny
  620.         # Other devices
  621.         OtherDevices -value $AllowDeny
  622.         # Let Apps Access My notifications
  623.         AppNotifications -value $AllowDeny
  624.         # Let apps access my call history
  625.         CallHistory -value $AllowDeny
  626.         # Let Apps access and send email
  627.         Email -value $AllowDeny
  628.         # Let apps access tasks
  629.         Tasks -value $AllowDeny
  630.         # Let apps access diagnostics of other apps
  631.         AppDiagnostics -value $AllowDeny
  632.         # Feedback & diagnostics        
  633.         if ($enable)
  634.         {
  635.             FeedbackFrequency -value -1
  636.         }
  637.         else
  638.         {
  639.             FeedbackFrequency -value 0
  640.         }
  641.  
  642.         # Edge
  643.  
  644.         DoNotTrack -value $OffOn
  645.         SearchSuggestions -value $OnOff
  646.         PagePrediction -value $OnOff
  647.         PhishingFilter -value $OnOff
  648.         StartTrackProgs -value $OnOff
  649.         TailoredExperiences -value $OnOff
  650.        
  651.     }
  652.  
  653.     Function Set-MiscPrivacyFeature([bool]$enable)
  654.     {            
  655.         #enabled for -default and -balanced disabled for -strong
  656.  
  657.         if ($enable)
  658.         {
  659.             SmartScreen -value 1
  660.             LanguageList -value 0
  661.         }
  662.         else
  663.         {
  664.             SmartScreen -value 0
  665.             LanguageList -value 1
  666.         }
  667.     }
  668.    
  669. }
  670. Process
  671. {
  672.     Write-Output "Processing settings..."
  673.  
  674.    
  675.     $myOS = Get-CimInstance -ClassName Win32_OperatingSystem -Namespace root/cimv2 -Verbose:$false
  676.  
  677.     if ([int]$myOS.BuildNumber -lt 10240)
  678.     {  
  679.         Write-Warning "Your OS version is not supported, Windows 10 or higher is required"
  680.         Exit 101
  681.     }
  682.  
  683.     $UserCurrent = [System.Security.Principal.WindowsIdentity]::GetCurrent()
  684.     $userIsAdmin = $false
  685.     $UserCurrent.Groups | ForEach-Object { if($_.value -eq "S-1-5-32-544") {$userIsAdmin = $true} }
  686.  
  687.     if ($Admin)
  688.     {        
  689.         if ($Strong)
  690.         {
  691.             ShareUpdates -value 0
  692.             WifiSense -value 0
  693.             Telemetry -enable $false
  694.             SpyNet -enable $false
  695.         }
  696.         if ($Balanced)
  697.         {
  698.             # allow LAN sharing of updates
  699.             ShareUpdates -value 1
  700.             WifiSense -value 0
  701.             Telemetry -enable $false
  702.             # in balanced mode, we don't disable SpyNet
  703.             SpyNet -enable $true
  704.         }
  705.         if ($Default)
  706.         {
  707.             ShareUpdates -value 3
  708.             WifiSense -value 1
  709.             Telemetry -enable $true
  710.             SpyNet -enable $true
  711.         }
  712.  
  713.         Report
  714.     }
  715.  
  716.     # this gets internal IDs for certain Apps like Cortana which we need in some functions
  717.     Get-AppSID
  718.  
  719.     if ($Strong)
  720.     {
  721.         # turn off as much as we can  
  722.         Set-MiscPrivacyFeature -enable $false
  723.         Set-StrictPrivacyFeature -enable $false        
  724.         Report        
  725.     }
  726.  
  727.     if ($Balanced)
  728.     {
  729.         Set-MiscPrivacyFeature -enable $true
  730.         Set-StrictPrivacyFeature -enable $false
  731.        
  732.         Report        
  733.     }
  734.  
  735.     if ($Default)
  736.     {
  737.         Set-MiscPrivacyFeature -enable $true
  738.         Set-StrictPrivacyFeature -enable $true  
  739.         Report
  740.     }
  741.  
  742.     # handle specific features
  743.  
  744.     $AllowDeny = "Deny"
  745.     $OnOff = 0
  746.     $OffOn = 1  
  747.     $DoEnable = $false  
  748.        
  749.     if ($Enable)
  750.     {
  751.         $AllowDeny = "Allow"
  752.         $OnOff = 1
  753.         $OffOn = 0
  754.         $DoEnable = $true
  755.     }
  756.  
  757.  
  758.     $Feature | ForEach-Object {
  759.  
  760.         switch ($_)
  761.             {
  762.                 "AdvertisingId" {AdvertisingId -value $OnOff;break}
  763.                 "ImproveTyping" {ImproveTyping -value $OnOff;break}
  764.                 "Location" {Location -value $AllowDeny;break}
  765.                 "Camera" {Camera -value $AllowDeny;break}
  766.                 "Microphone" {Microphone -value $AllowDeny;break}
  767.                 "SpeachInkingTyping" {SpeachInkingTyping -enable $DoEnable;break}
  768.                 "AccountInfo" {AccountInfo -value $AllowDeny;break}
  769.                 "Contacts" {Contacts -value $AllowDeny;break}
  770.                 "Calendar" {Calendar -value $AllowDeny;break}
  771.                 "Messaging" {Messaging -value $AllowDeny;break}
  772.                 "Radios" {Radios -value $AllowDeny;break}
  773.                 "OtherDevices" {OtherDevices -value $AllowDeny;break}
  774.                 "AppNotifications" {AppNotifications -value $AllowDeny;break}
  775.                 "CallHistory" {CallHistory -value $AllowDeny;break}
  776.                 "Email" {Email -value $AllowDeny;break}
  777.                 "Tasks" {Tasks -value $AllowDeny;break}
  778.                 "AppDiagnostics"{AppDiagnostics -value $AllowDeny;break}
  779.                 "FeedbackFrequency" {
  780.                         if ($Enable) {
  781.                             FeedbackFrequency -value -1;
  782.                         }
  783.                         else
  784.                         {
  785.                             FeedbackFrequency -value 0;
  786.                         }
  787.                         break}
  788.                 "ShareUpdates" {
  789.                         if ($Enable) {
  790.                             ShareUpdates -value 3;
  791.                         }
  792.                         else
  793.                         {
  794.                             ShareUpdates -value 0;
  795.                         }
  796.                         break}
  797.                 "WifiSense" {WifiSense -value $OnOff;break}                                                                    
  798.                 "Telemetry" {Telemetry -enable $DoEnable;break}
  799.                 "SpyNet" {SpyNet -enable $DoEnable ;break}
  800.                 "DoNotTrack" {DoNotTrack -value $OffOn;break}  
  801.                 "SearchSuggestions" {SearchSuggestions -value $OnOff;break}  
  802.                 "PagePrediction" {PagePrediction -value $OnOff;break}  
  803.                 "PhishingFilter" {PhishingFilter -value $OnOff;break}  
  804.                 "StartTrackProgs" {StartTrackProgs -value $OnOff;break}
  805.                 "TailoredExperiences"{TailoredExperiences -value $OnOff;break}
  806.                 default {"ooops, nothing selected"}
  807.             }
  808.     }
  809.  
  810. }
  811. End
  812. {
  813.  
  814.  
  815. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement