Created
November 28, 2017 02:24
-
-
Save theinventor/7b9f2e1f96420291db28592727ede8d3 to your computer and use it in GitHub Desktop.
Powershell to install and run ccleaner. In Syncro set this up to run as System, Powershell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?