#update the below variables to match your environment $global:fqdn = "" #Example fqdn = "demo.loginvsi.com" $global:token = '' #Example token = 'f_Yl7m-9XncLQNA6BmPAY21lP0BCMzm7FzHyH2t4WQg' $global:response = " " $launcherlocation = "C:\Program Files\Login VSI\Login Enterprise Launcher\LoginEnterprise.Launcher.UI.exe" $date=get-date #Add-Content "C:\Custom_Connector\Launcherverify_logs\log.txt" $date option line for additional troubleshooting #Define our functions, these will access the API and return a list of launchers, note line 16 may need to be adjusted in large environments. function Get-LeLauncher { Param ( [Parameter(Mandatory = $true)] [string]$orderBy = "Name", [string]$Direction = "Asc", [string]$Count = "100" ) # this is only required for older version of PowerShell/.NET [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls11 # WARNING: ignoring SSL/TLS certificate errors is a security risk # [System.Net.ServicePointManager]::ServerCertificateValidationCallback = [SSLHandler]::GetSSLHandler() $Header = @{ "Accept" = "application/json" "Authorization" = "Bearer $global:token" } $Body = @{ orderBy = $orderBy direction = $Direction count = $Count } $Parameters = @{ Uri = 'https://' + $global:fqdn + '/publicApi/v5/launchers/' Headers = $Header Method = 'GET' body = $Body ContentType = 'application/json' } $Response = Invoke-RestMethod @Parameters $Response.items } $mName = $env:COMPUTERName #Gets the machine name, this is how the launcher is identified. # Add-Content "C:\Custom_Connector\Launcherverify_logs\log.txt" $mName optional debugging line $Launchers = Get-LeLauncher -orderby Name | Where {$_.machineName -eq $mName} foreach ($Launcher in $Launchers){ Write-host $launcher.machineName "Is online? " $launcher.online #manual Verification for testing Add-Content "C:\Custom_Connector\Launcherverify_logs\log.txt" $launcher.online } //if the launcher/Machine name is not found restart the launcher process if($launchers -eq $Null){ try{ Get-Process -Name "loginPI*" | Stop-Process Add-Content "C:\Custom_Connector\Launcherverify_logs\log.txt" "Process Stopped succesfully" } catch{ Add-Content "C:\Custom_Connector\Launcherverify_logs\log.txt" "Process failed to stop" } start-process $LauncherLocation write-host "Launcher was restarted" start-sleep -s 30 $Launchers = Get-LeLauncher -orderby Name | Where {$_.machineName -eq $mName} if($launchers -eq $Null){ # Add-Content "C:\Custom_Connector\Launcherverify_logs\log.txt" "Launcher Restart failed"} #optional debug line else{ # Add-Content "C:\Custom_Connector\Launcherverify_logs\log.txt" "Launcher Restart Suceeded"} #optional debug line } else{ # Add-Content "C:\Custom_Connector\Launcherverify_logs\log.txt" "Launcher is running" #optional debug line }