40 lines
1.3 KiB
PowerShell
40 lines
1.3 KiB
PowerShell
# Directories to search
|
|
$searchPaths = @(
|
|
"C:\Windows\ccmcache",
|
|
"C:\Windows\Temp\Ivanti"
|
|
|
|
)
|
|
|
|
# Filename to search for
|
|
$fileName = "NCH-Pulse-Secure.pulsepreconfig"
|
|
|
|
# Command to run if file is found
|
|
$jamCommandPath = "C:\Program Files (x86)\Common Files\Pulse Secure\JamUI\jamCommand.exe"
|
|
|
|
# Flag to track if the command has been executed
|
|
$commandExecuted = $false
|
|
|
|
foreach ($path in $searchPaths) {
|
|
if (-not $commandExecuted) {
|
|
# Get all files that match the given filename in the target directory and subdirectories
|
|
Get-ChildItem -Path $path -Recurse -Filter $fileName -ErrorAction SilentlyContinue | ForEach-Object {
|
|
$filePath = $_.FullName
|
|
Write-Host "Found file: $filePath"
|
|
|
|
# Run the JamCommand with the found file as parameter using Start-Process
|
|
Start-Process -FilePath $jamCommandPath -ArgumentList "-importfile `"$filePath`"" -Wait
|
|
Write-Host "Executed: $jamCommandPath -importfile $filePath"
|
|
Restart-Service -Name PulseSecureService
|
|
|
|
# Set the flag to true, so it doesn't execute again
|
|
$commandExecuted = $true
|
|
|
|
# Break the loop since we don't need to process further
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
if (-not $commandExecuted) {
|
|
Write-Host "No file found for execution."
|
|
} |