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

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Ed O'Connor Ed O’Connor 9 months, 3 weeks ago.

  • Author
    Posts
  • #35110
    Profile photo of Ed O'Connor
    Ed O’Connor
    Participant

    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
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    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}
    }
    $AllFWdisabled

  • #35113
    Profile photo of Ed O'Connor
    Ed O’Connor
    Participant

    That did the trick.

    Thank you very much.

You must be logged in to reply to this topic.