TestScript for disabling Windows Firewall Profiles

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Ed O'Connor Ed O’Connor 7 months, 3 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #34929
    Profile photo of Ed O'Connor
    Ed O’Connor
    Participant

    Hi,

    I am using the DSC Script resource to disable all the Windows Firewall Profiles. The set script of it works perfectly as it cycles through the firewall profiles and if any have the enabled notlike 'false' it sets it to false.

    I know needs to result with a 'True' (which means the set script portion will not run) or 'False' which then runs the set script portion.

    Here is my script resource:

     #Ensures Windows Firewall Profiles are disabled
            Script "Windows Firewall Profiles are disabled"
            {
              SetScript = {
                $DisableFWProfiles = $Null
                $DisableFWProfiles = Get-NetFirewallProfile -Profile * | select-object name,enabled
    
    			Foreach ($FWProfile in $DisableFWProfiles) {
    
    				If ($FWProfile.Enabled -notlike "False") {Set-NetFirewallProfile -Profile $FWProfile.Name -enabled false}
    			}
            }
            TestScript = {
              #false
              $DisableFWProfiles = $Null
              $DisableFWProfiles = Get-NetFirewallProfile -Profile * | select-object name,enabled 
    
              Foreach ($FWProfile in $DisableFWProfiles) {
    
                If ($FWProfile.Enabled -like "false") {$True}
    			Else {$false}
            }
    		}
            GetScript = {
            return @{Result="Disables the Firewall Profiles"}
        }
        }
    

    I have the TestScript set up it will loop through each profile and result a true or false. If I get a true response before any falses the setscript never runs.

    How can I get this to show true or false based on the results of all loop (each profile)?

    Basically I want if any of the profiles show false; for the TestScript to result in false.

    thanks in advance for your help. Hopefully, no one thinks this is a silly question.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.