TestScript for disabling Windows Firewall Profiles

Welcome Forums DSC (Desired State Configuration) TestScript for disabling Windows Firewall Profiles

Viewing 0 reply threads
  • Author
    Posts
    • #34929
      Participant
      Topics: 27
      Replies: 51
      Points: 0
      Rank: Member

      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 0 reply threads
  • The topic ‘TestScript for disabling Windows Firewall Profiles’ is closed to new replies.