Skip to main content

Powershell functions to uninstall anyconnect modules

#Script Version
$sScriptVersion = "1.0"
#script root

$PSScriptRoot = ($MyInvocation.MyCommand.Path | Split-Path | Resolve-Path).ProviderPath

#logging variables.
$logdir = "$($env:ALLUSERSPROFILE)\InstallLogs"
$Logfile = "$($logdir)\remove_anyconnect_$(get-date -format `"yyyyMMdd_hhmmsstt`").log"

Function LogWrite($string, $color)
   if ($Color -eq $null) {$color = "white"}
   write-host $string -foregroundcolor $color
   $string | out-file -Filepath $logfile -append

if(!(Test-Path -Path $logdir )){
    New-Item -ItemType directory -Path $logdir

$CP_USER_NAME = (Get-WmiObject Win32_ComputerSystem | Select-Object -ExpandProperty UserName).Split('\')[1]
$user = New-Object System.Security.Principal.NTAccount("corp", "$CP_USER_NAME") 
$sid = $user.Translate([System.Security.Principal.SecurityIdentifier]) 
$userprofile = Get-WmiObject -Namespace root/cimv2 -Class win32_userprofile -Filter "SID='$($sid.value)'"
$CP_USER_HOME = $userprofile.localpath

function stopservices(){
get-service 'ciscod.exe', 'acwebsecagent' | ? { $_.Status -eq 'Started'  } | % {
  $_ | stop-service
  sleep 1
  $result = if (($_ | get-service).Status -eq "Running") {"success"} else {"failure"}
  LogWrite "Service stopped $result"

Function acuninstall()
            $uninstallerfile = "$PSScriptRoot\Uninstall.exe"
            $UninstallSyntax = "-remove -silent"
            $process = Start-Process $uninstallerfile -ArgumentList $UninstallSyntax -Wait -Passthru

            if ($process.ExitCode -eq 0) {
                 LogWrite "AnyConnect has been successfully uninstalled" yellow
            else {
                LogWrite "installer exit code  $($process.ExitCode) for AnyConnect" red

Function dartuninstall()
    $dart = Get-WmiObject -Namespace "root\cimv2\sms" -Class SMS_InstalledSoftware | where { $_.ARPDisplayName -match "Cisco AnyConnect Diagnostics" }
    $uninst = $dart.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
    $dartuninstallcode = $uninst.Trim()
 Start-Process "msiexec.exe" -arg "/X $dartuninstallcode /passive /norestart" -Wait

function startbeforeloginuninstall()
 $startbeforelogin = Get-WmiObject -NameSpace "root\cimv2\sms" -class SMS_InstalledSoftware | where { $_.ARPDisplayName -match "Cisco AnyConnect Start Before Login Module"}
 $startbeforeloginuninst = $startbeforelogin.UninstallString -Replace "msiexec.exe", "" -Replace "/I", "" -Replace "/X", ""
 $startbeforeloginuninstcode = $startbeforeloginuninst.Trim()
 Start-Process "msiexec.exe" -arg "/X $startbeforeloginuninstcode /passive /norestart" -Wait

function websecurityuninstall()
 $websecuritylogin = Get-WmiObject -NameSpace "root\cimv2\sms" -class SMS_InstalledSoftware | where { $_.ARPDisplayName -match "Cisco AnyConnect Web Security Module" }
 $websecurityuninst = $websecuritylogin.UninstallString -Replace "msiexec.exe", "" -Replace "/I", "" -Replace "/X", ""
 $websecurityuninstcode = $websecurityuninst.Trim()
 Start-Process "msiexec.exe" -arg "/X $websecurityuninstcode /passive /norestart" -Wait

function postureuninstall()
 $posturelogin = Get-WmiObject -NameSpace "root\cimv2\sms" -class SMS_InstalledSoftware | where { $_.ARPDisplayName -match "Cisco AnyConnect Posture Module" }
 $postureuninst = $posturelogin.UninstallString -Replace "msiexec.exe", "" -Replace "/I", "" -Replace "/X", ""
 $postureuninstcode = $postureuninst.Trim()
 Start-Process "msiexec.exe" -arg "/X $postureuninstcode /passive /norestart" -Wait

function telemetryuninstall()
 $telemetrylogin = Get-WmiObject -NameSpace "root\cimv2\sms" -class SMS_InstalledSoftware | where { $_.ARPDisplayName -match "Cisco AnyConnect Telemetry Module" }
 $telemetryuninst = $telemetrylogin.UninstallString -Replace "msiexec.exe", "" -Replace "/I", "" -Replace "/X", ""
 $telemetryuninstcode = $telemetryuninst.Trim()
 Start-Process "msiexec.exe" -arg "/X $telemetryuninstcode /passive /norestart" -Wait
function namuninstall()
 $namlogin = Get-WmiObject -NameSpace "root\cimv2\sms" -class SMS_InstalledSoftware | where { $_.ARPDisplayName -match "Cisco AnyConnect Network Access Manager" }
 $namuninst = $namlogin.UninstallString -Replace "msiexec.exe", "" -Replace "/I", "" -Replace "/X", ""
 $namuninstcode = $namuninst.Trim()
 Start-Process "msiexec.exe" -arg "/X $namuninstcode /passive /norestart" -Wait

function anyconnectuninstall()
 $anyconnectlogin = Get-WmiObject -NameSpace "root\cimv2\sms" -class SMS_InstalledSoftware | where { $_.ARPDisplayName -match "Cisco AnyConnect Secure Mobility Client" }
 $anyconnectuninst = $anyconnectlogin.SoftwareCode
 $anyconnectuninstcode = $anyconnectuninst.Trim()
 Start-Process "msiexec.exe" -arg "/X $anyconnectuninstcode /passive /norestart" -Wait


Popular posts from this blog

Removing corporate wireless restrictions completely : "The policies of your network prevent the creation of ad hoc (computer-to-computer) networks. For more information, contact your system administrator."

So i was recently tasked with removing wireless restrictions from a VP's windows 7 laptop that some infrastructure company had placed while contracted with our network, since he needed to enable setting up of adhoc connections on his laptop and he always got

"The policies of your network prevent the creation of ad hoc (computer-to-computer) networks. For more information, contact your system administrator."

A little bit of probing revealed that adhoc and peer to peer connections were blocked as evidenced by the the command 

netsh wlan show filter on an  elevated command prompt revealed that adhoc network type was blocked by group policy:

I removed the restrictions by:

1: open services.msc as administrator, scroll down to WLAN AutoConfig:

To Unlock Windows Update locked due to group policy.

To Unlock Windows Update locked due to group policy.

Open gpedit.msc and browse to the location /Computer Configuration/Administrative Templates/System/Internet Communication Management/Internet Communication Settings and double click "turn off access to all windows update features" and set it to disabled.

Migrating Outlook Profile to Office 365

We had a migration from Hosted Exchange to Office 365 and i was tasked with automating the local Outloook profile migration for Users:

I Created a GUI utility using powershell which would allow users to create an Office365 Profile and set it as default, I prepared PRF files for each version of office and an autodiscover.xml to be used for local autodiscover and uploaded them to a hosted site:

The PRF file to set settings for Office 365 are hard to find: i used the below entries: