Add success/failure test to scripts

Hi Support,

Here are the tasks/deployments I used for transitioning users from Sophos SSL VPN Client to Sophos Connect client. I need them either combined or at least modified to include the required checks for ImmyBot to report accurate success/failure of each (They would always report as failed in their current state, despite executing successfully):
(When I tried to combine these tasks/scripts, it would fail to execute correctly. Not sure if a wait function between each is all that is needed)

Kill Sophos SSL VPN Client (Task - Powershell):

taskkill /IM openvpn.exe /F
taskkill /IM openvpnserv.exe /F
taskkill /IM openvpn-gui.exe /F

Uninstall Sophos SSL VPN Client (Task - Poweshell):

Start-Process -FilePath "C:\Program Files (x86)\Sophos\Sophos SSL VPN Client\Uninstall.exe" -ArgumentList "/S /qn"
Remove-Item -LiteralPath "C:\Program Files (x86)\Sophos\Sophos SSL VPN Client\config" -Force -Recurse
Remove-Item -LiteralPath "C:\Program Files (x86)\Sophos\Sophos SSL VPN Client\log" -Force -Recurse
Remove-Item -LiteralPath "C:\Program Files (x86)\Sophos\Sophos SSL VPN Client" -Force -Recurse

Sophos Connect – No Provisioning (Deployment) (no change needed*)

Sophos Connect provisioning file – File in Specific Location (Task – Powershell):
Parameters:

File: VPN Setup.pro
Location: AllUsersDesktop

Script:

$Destination = Invoke-ImmyCommand {
    switch($Using:Location) {
        "AllUsersDesktop" {
            $Destination = "$($env:Public)\Desktop"
        }
        "WindowsFolder" {
            $Destination = "$($env:SystemRoot)"
        }
        "OtherLocation" {
            $Destination = "$($Using:OtherLocation)"
        }
    }
    return $Destination
}

$File | FileShould-Be -InPath $Destination

I need the above tasks to have the tests that tell ImmyBot if they succeeded/failed, as well as being combined, if possible.


I also have a separate task which I need to run after the migrations are complete, which removes provisioning file after the user does not need it anymore:
(It works, but I also need the appropriate tests added to this script which notify ImmyBot if it succeeded/failed so we get confirmation if it succeeded/failed)

Remove VPN Setup file (Task – Powershell):

foreach($userfolder in (get-childitem "c:\users" -Name)){
    $currentuserpath = "C:\Users\"+$userfolder+"\Desktop\VPN Setup.pro"
    if (!(Test-Path $currentuserpath)) {
        Write-Host "$currentuserpath does not exist. Skipped"
        continue
    }
    else {
        $RemovedSuccessfully = Remove-Item $currentuserpath -Force -ErrorAction SilentlyContinue
        Write-Host "$currentuserpath deleted."
    }
}
return $true

Let me know if you have any questions or need additional information.

@SFuse ,

Here’s the approach I’d recommend taking:

  1. Create a software with an uninstall script for Sophos SSL VPN Client, and check for the existence and remove the VPN setup files using Invoke-HKCU
  2. Run the uninstall with the newly created software
  3. Run the install for the existing Sophos Connect client

If you do it the way you have it, you essentially have a “one time use” task that you’ll probably never use again, vs having distinct items that you can put together and use in whatever combination in the future you might need them.

As for “needing to write tests,” you need to know what exactly to test for–there are hundreds of task scripts that demonstrate how to write tests–all it amounts to is putting $true or $false in the output stream for each test you want to write, and if Immy sees a $false in the output stream, then it will proceed to the “set” (or enforcement) part of the deploment–which, in a combined script is simply $method is made equal to “set” by Immy so you know whether you are “testing” or “setting.”