How to get CimInstance of specific NetFirewallProfile with powershell 4?

I try to automate enabling existing firewall rule that allows to use MS DTC for Domain "network type" like throug GUI enter image description here

Enable-NetFirewallRule –DisplayGroup “Distributed Transaction Coordinator”

sets all checkboxes

Cmdlet Enable-NetFirewallRule has AssociatedNetFirewallProfile parameter but it's of type CimInstance not String. There is also Get-NetFirewallProfile but I cannot use it to populate the parameter nor through pipeline neither as variable.


Instead of trying to fetch the profile and supplying it, you can use Get-NetFirewallRule to find the rule (with the profile) and pipe it into Enable-NetFirewallRule.

As an example you could use the following, assuming that "Distributed Transaction Coordinator" is the name of the actual rule:

Get-NetFirewallRule | Where {$_.Name -eq "Distributed Transaction Coordinator" -and $_.Profile -eq "Domain"} | Enable-NetFirewallRule

Furthermore you should be able to use Get-NetFirewallProfile to fetch the object of a profile into a variable and supply it.

| improve this answer | |
  • Filtering Get-NetFirewallRule solved my problem. Thanks. Your second suggestion I mentioned in last sentence of my original post - it does not work for me. – SerG May 23 '17 at 12:31
  • Now I've figured it out that those rules were existed due to my first experiments with GUI. On clean system I need to create them not just enable. – SerG May 24 '17 at 15:36
  • 1
    Careful with the $_Profile -eq "Domain" -- Profile is actually an enum, and if it's set to Domain and another profile (e.g. Private), then the -eq won't work. – CJBS Jun 10 '19 at 5:35
  • 1
    Good point. Profile is actually a Microsoft.PowerShell.Cmdletization.GeneratedTypes.NetSecurity.Profile but there seems to be an implicit conversion to a string. As such an easy workaround would be to use -like '*Domain*' instead of -eq. – Seth Jun 12 '19 at 6:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.