Last active
October 31, 2018 00:05
-
-
Save CMCDragonkai/dbd2d94840cdaf79d3f6964bbd58e92f to your computer and use it in GitHub Desktop.
Set Firewall Profiles for Identified Network Connections #windows #powershell #cli
This file contains 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
#!/usr/bin/env powershell | |
#requires -RunAsAdministrator | |
# Unidentified network connections will not show here | |
# To make an unidentified network connection identified, you must add a gateway address | |
# Not all profiles shown here will be active | |
# https://blogs.technet.microsoft.com/networking/2010/09/08/network-location-awareness-nla-and-how-it-relates-to-windows-firewall-profiles/ | |
param ( | |
[string]$ID = $null, | |
[string]$Name = $null, | |
[string]$Description = $null, | |
[ValidateSet('Public', 'Private')]$Category = $null | |
) | |
if ($ID) { | |
$ProfileKey = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles\{$ID}" | |
if (Test-Path -Path "$ProfileKey") { | |
if ($Name) { | |
Set-ItemProperty -Path "$ProfileKey" -Name 'ProfileName' -Value "$Name" | |
} | |
if ($Description) { | |
Set-ItemProperty -Path "$ProfileKey" -Name 'Description' -Value "$Description" | |
} | |
if ($Category) { | |
switch ($Category) { | |
'Public' { | |
Set-ItemProperty -Path "$ProfileKey" -Name 'Category' -Value 0 -Type DWord | |
} | |
'Private' { | |
Set-ItemProperty -Path "$ProfileKey" -Name 'Category' -Value 1 -Type DWord | |
} | |
} | |
} | |
} else { | |
Write-Host "Network Profile {$ID} does not exist!" | |
Exit 3 | |
} | |
} else { | |
Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Profiles' ` | |
| ForEach-Object { Get-ItemProperty $_.PSPath } ` | |
| Select-Object -Property ` | |
@{Label = "ID"; Expression = { $_.PSChildName.Trim('{}') }}, ` | |
@{Label = "Name"; Expression = { $_.ProfileName }}, ` | |
Description, ` | |
@{Label = "Category"; Expression = { | |
switch ($_.Category) { | |
0 {"Public"} | |
1 {"Private"} | |
2 {"Domain"} | |
} | |
}}, ` | |
Managed ` | |
| Format-Table | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment