Posted On May 21, 2020

PowerShell: Disable Forticlient Web Filtering

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Disable Forticlient Web Filtering
# disableForticlientWebfiltering.ps1
# Note: untested script - use as sample as this snippet is incomplete

$forticlientConfigFile="\\FILESHERVER009\forticlient.config"

function confirmation($content,$testValue="I confirm",$maxAttempts=3){
    $confirmed=$false;
    $attempts=0;        
    $content|write-host
    write-host "Please review this content for accuracy.`r`n"
    while ($attempts -le $maxAttempts){
        if($attempts++ -ge $maxAttempts){
            write-host "A maximum number of attempts have reached. No confirmations received!`r`n"
            break;
            }
        $userInput = Read-Host -Prompt "Please type in this value => $testValue <= to confirm";
        if ($userInput.ToLower() -ne $testValue.ToLower()){
            cls;
            $content|write-host
            write-host "Attempt number $attempts of $maxAttempts`: $userInput does not match $testValue. Try again..`r`n"
            }else{
                $confirmed=$true;
                write-host "Confirmed!`r`n";
                break;
                }
        }
    return $confirmed;
}

function disableForticlientWebfiltering($forticlientConfigFile){    
    $forticlientConfig=get-content $forticlientConfigFile
    $hasWebfilterSettings=$forticlientConfig -match 'webfilter'

    if($hasWebfilterSettings){
        $forticlientConfig=$forticlientConfig -replace '<enable_filter>\d{1}','<enable_filter>0'
        }else{
        $webFilter=@"
    <webfilter>
        <enable_filter>0</enable_filter> 
    </webfilter>
</configuration>
"@
        $forticlientConfig=$forticlientConfig -replace '</configuration>',$webFilter
        }
    
    $confirmOverwrite=confirmation -content $forticlientConfig
    if($confirmOverwrite){
        $backupFile=$forticlientConfigFile+"_backup"
        try{
            Rename-Item -Path $forticlientConfigFile -NewName $backupFile -ErrorAction Stop
            }
            catch{
                Remove-item $backupFile -Force
                Rename-Item -Path $forticlientConfigFile -NewName $backupFile
                }
        $forticlientConfig|set-Content $forticlientConfigFile
        write-host "$record has been added to $hostfile successfully."
        return $true
        }else{
            write-host "No changes were made as there were no confirmations."
            return $false;
            }
        
}

disableWebfiltering

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Administering Network Time Protocol Settings on Windows

Quick Script of Domain Joined Laptops and Desktops for Remote Users: # Set Domain Joined…

Basic HTML and HTML5: Nest an Anchor Element within a Paragraph

<h2>CatPhotoApp</h2><main><a href="http://freecatphotoapp.com" target="_blank">cat photos</a><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying on its back."><p>Kitty ipsum dolor…

PowerShell: Create A Shortcut on Everyone’s Desktop

Following is an example of a 'how to create a log-off button on Everyone's desktop'.…