Skip to content

Instantly share code, notes, and snippets.

@karimelmel
Last active February 13, 2021 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karimelmel/849e43e93aa015f0e57069ed3d7458c7 to your computer and use it in GitHub Desktop.
Save karimelmel/849e43e93aa015f0e57069ed3d7458c7 to your computer and use it in GitHub Desktop.
$blockPrincipal = New-Object -TypeName System.Security.Principal.NTAccount ("Everyone")
$BlockPrincipalSID = $blockPrincipal.Translate([System.Security.Principal.SecurityIdentifier]).Value
$exceptionPrincipal = New-Object -TypeName System.Security.Principal.NTAccount ("Administrators")
$ExceptionPrincipalSID = $exceptionPrincipal.Translate([System.Security.Principal.SecurityIdentifier]).Value
$PrincipalSDDL = "O:LSD:(D;;CC;;;$ExceptionPrincipalSID)(A;;CC;;;$BlockPrincipalSID)"
New-NetFirewallRule -DisplayName "Block metatdata service for $($blockPrincipal.Value), exception: $($exceptionPrincipal.Value)" `
-Action Block `
-Direction Outbound `
-Protocol TCP `
-RemoteAddress 169.254.169.254 `
-LocalUser $PrincipalSDDL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment