How to make Intune run scripts sequentially?
I have two scripts and both of them will reside in the C:\ directory of the remote devices using Intune. One script is to delete the Google cache and the other script is to create a scheduled task of the script to delete Google's cache.
But I need the script to create the scheduled task to run first in Intune because it calls the script to delete the cache.
Is there a way to make Intune do that?
Here's the script to create the scheduled task.
$action = New-ScheduledTaskAction -Execute 'Powershell.exe' -Argument 'deleteGoogleCache.ps1'
$trigger = New-ScheduledTaskTrigger -Daily -At 11pm
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName "DeleteGoogleCache" -Description "This delete google's cache daily."
Here's the script that deletes the cache
# Define the path to the Chrome cache folder
$chromeCachePath = "$env:LOCALAPPDATA\Google\Chrome\User Data\Default\Cache"
# Check if the cache folder exists
if (Test-Path $chromeCachePath) {
try {
# Remove all files and folders in the cache directory
Remove-Item -Path $chromeCachePath\* -Recurse -Force
Write-Output "Chrome cache has been deleted successfully."
} catch {
Write-Output "An error occurred while deleting Chrome cache: $_"
}
} else {
Write-Output "Chrome cache folder does not exist."
}