Report $True or $False based on a collection of results

This topic contains 2 replies, has 2 voices, and was last updated by  Ed O’Connor 2 years, 5 months ago.

  • Author
  • #35110

    Ed O’Connor

    Hello all,

    I am trying to create a verification that reports $True is all of the Firewall Profiles are disabled or $False if any of they show as enabled.

    Basically I run:

              $DisableFWProfiles = $Null
              $DisableFWProfiles = Get-NetFirewallProfile -Profile * | select-object name,enabled 

    This will give me a result as such:

    name Enabled
    ——— ————-
    Domain False
    Private True
    Public False

    What I am looking for is:
    if all profiles return "Enabled = False" then to return $True
    if any of the profiles return "Enabled = True" then to return $False

    I tried this but it give me three $True/$False returns

              $DisableFWProfiles = $Null
              $DisableFWProfiles = Get-NetFirewallProfile -Profile * | select-object name,enabled 
              Foreach ($FWProfile in $DisableFWProfiles) {
                If ($FWProfile.Enabled -like "false") {$True}
    			Else {$false}

    All help is greatly appreciated.

  • #35112

    Richard Siddaway

    If I've understood your question correctly this should give you what you want

    $AllFWdisabled = $true

    Get-NetFirewallProfile |
    foreach {
    if ($psitem.Enabled -eq 'True') {$AllFWdisabled = $false}

  • #35113

    Ed O’Connor

    That did the trick.

    Thank you very much.

You must be logged in to reply to this topic.