{"id":4106,"date":"2019-05-09T06:49:09","date_gmt":"2019-05-09T06:49:09","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=4106"},"modified":"2024-03-13T23:54:34","modified_gmt":"2024-03-13T23:54:34","slug":"intune-powershell-script-to-set-all-windows-10-connectoins-to-unmetered","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/code\/intune-powershell-script-to-set-all-windows-10-connectoins-to-unmetered","title":{"rendered":"Intune Powershell Script to Set All Windows 10 Connectoins to UnMetered"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code class=\"\">#AllConnectionsUnMetered\r\n\r\n#We need a Win32 class to take ownership of the Registry key\r\n$definition = @\"\r\nusing System;\r\nusing System.Runtime.InteropServices; \r\n \r\nnamespace Win32Api\r\n{\r\n \r\n    public class NtDll\r\n    {\r\n        [DllImport(\"ntdll.dll\", EntryPoint=\"RtlAdjustPrivilege\")]\r\n        public static extern int RtlAdjustPrivilege(ulong Privilege, bool Enable, bool CurrentThread, ref bool Enabled);\r\n    }\r\n}\r\n\"@ \r\n \r\nAdd-Type -TypeDefinition $definition -PassThru | Out-Null\r\n[Win32Api.NtDll]::RtlAdjustPrivilege(9, $true, $false, [ref]$false) | Out-Null\r\n \r\n#Setting ownership to Administrators\r\n$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey(\"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\DefaultMediaCost\",[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::takeownership)\r\n$acl = $key.GetAccessControl()\r\n$acl.SetOwner([System.Security.Principal.NTAccount]\"Administrators\")\r\n$key.SetAccessControl($acl)\r\n \r\n#Giving Administrators full control to the key\r\n$rule = New-Object System.Security.AccessControl.RegistryAccessRule ([System.Security.Principal.NTAccount]\"Administrators\",\"FullControl\",\"Allow\")\r\n$acl.SetAccessRule($rule)\r\n$key.SetAccessControl($acl)\r\n\r\nNew-ItemProperty -path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\DefaultMediaCost\" -Name WiFi -PropertyType Dword -Value 1 -Force\r\nNew-ItemProperty -path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\DefaultMediaCost\" -Name 3G -PropertyType Dword -Value 1 -Force\r\nNew-ItemProperty -path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\DefaultMediaCost\" -Name 4G -PropertyType Dword -Value 1 -Force\r\nNew-ItemProperty -path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\DefaultMediaCost\" -Name Ethernet -PropertyType Dword -Value 1 -Force\r\nNew-ItemProperty -path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\NetworkList\\DefaultMediaCost\" -Name Default -PropertyType Dword -Value 1 -Force<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320,2836],"tags":[],"class_list":["post-4106","post","type-post","status-publish","format-standard","hentry","category-code","category-intune"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/4106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=4106"}],"version-history":[{"count":3,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/4106\/revisions"}],"predecessor-version":[{"id":7779,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/4106\/revisions\/7779"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=4106"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=4106"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=4106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}