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: Excute Function Remotely

$computername=$env:computerName $adminUsername='doeMainAdmin' $adminPassword='frackingPassword' $adminCredential=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $adminUsername,$(ConvertTo-securestring $adminPassword -AsPlainText -Force) function execFunctionRemotely{ param( [Parameter(Mandatory=$true)][string]$computerName,…

PowerShell: Script to Stop, Start, Disable, and Enable Exchange Server

<#This script contains a set of functions to administer Exchange 2010, 2013, 2016, and 3000.…

PowerShell: Obtain Date Time Stamp And Convert to Pacific Standard Zone

# 1-liner date stamp $dateStamp=[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId( (Get-Date), 'Pacific Standard Time').tostring("MM-dd-yyyy-HHmm")+'_PST' #sample output #06-15-2020-1949_PST $timeZone='Pacific Standard Time'…
Other project: DragonCoin.com