Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Powershell to install and run ccleaner. In Syncro set this up to run as System, Powershell.
Import-Module $env:SyncroModule
# Silent Install CCleaner
# http://www.piriform.com/ccleaner/download
# Path for the workdir
$workdir = "c:\temp\"
$sixtyFourBit = Test-Path -Path "C:\Program Files (x86)"
$cCleanerInstalled = Test-Path -Path "C:\Program Files\CCleaner"
If ($cCleanerInstalled){
Write-Host "Installed - running the cleaner!"
Start-Process -FilePath "C:\Program Files\CCleaner\CCleaner64.exe" -ArgumentList "/AUTO /SHUTDOWN"
} ELSE {
Write-Host "Doing the installation first"
# Check if work directory exists if not create it
If (Test-Path -Path $workdir -PathType Container){
Write-Host "$workdir already exists" -ForegroundColor Red
} ELSE {
New-Item -Path $workdir -ItemType directory
}
# Download the installer
$source = "http://download.piriform.com/ccsetup537.exe"
$destination = "$workdir\ccsetup.exe"
# Check if Invoke-Webrequest exists otherwise execute WebClient
if (Get-Command 'Invoke-Webrequest'){
Invoke-WebRequest $source -OutFile $destination
} else {
$WebClient = New-Object System.Net.WebClient
$webclient.DownloadFile($source, $destination)
}
# Start the installation
Start-Process -FilePath "$workdir\ccsetup.exe" -ArgumentList "/S"
Start-Sleep -s 35
Start-Process -FilePath "C:\Program Files\CCleaner\CCleaner64.exe" -ArgumentList "/AUTO /SHUTDOWN"
}
@surepointit

This comment has been minimized.

Copy link

@surepointit surepointit commented Nov 28, 2017

If CCleaner is already installed and there is a very old version, how can you script that to update to the latest version? Also, how can we output what was actually cleaned up after it runs? If we can't pull logs, what exactly does the /AUTO argument do to the machine it is run on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.