Select Page

Required Files: SharedScriptRequiredFile 23


This script was based off the template Bleachbit script in the repository. I modified what it cleans (see below), and have had it create a ticket, add ticket time (10 minutes which you can change), and close the ticket.

I have modified it so that it cleans the following:
System Files (temp files)
Firefox Cache
Google Chrome Cash
Internet Explorer Temporary Files
Flash Cache
Java Cache


 

Import-Module $env:SyncroModule
$subdomain = "yoursubdomain"
$email = "[email protected]"
 
# Create Ticket and get the ticket number
$varTicket = Create-Syncro-Ticket -Subdomain $subdomain -Subject "Cleanup for $env:computername" -IssueType "Other" -Status "New"
$ticket = $varTicket.ticket.number
 
# Add time to ticket
$startAt = (Get-Date).AddMinutes(-30).toString("o")
Create-Syncro-Ticket-TimerEntry -Subdomain "$subdomain" -TicketIdOrNumber $ticket -StartTime $startAt -DurationMinutes 15 -Notes "Automated system cleaned up the disk space." -UserIdOrEmail "$email"
 
 
# Get disk space available BEFORE the Cleanup
$Before = Get-WmiObject Win32_LogicalDisk | Where-Object { $_.DriveType -eq "3" } | Select-Object SystemName,
@{ Name = "Drive" ; Expression = { ( $_.DeviceID ) } },
@{ Name = "Size (GB)" ; Expression = {"{0:N1}" -f( $_.Size / 1gb)}},
@{ Name = "FreeSpace (GB)" ; Expression = {"{0:N1}" -f( $_.Freespace / 1gb ) } },
@{ Name = "PercentFree" ; Expression = {"{0:P1}" -f( $_.FreeSpace / $_.Size ) } } |
Format-Table -AutoSize | Out-String  
 
# Perform Cleanup Tasks
Expand-Archive C:\temp\bleachbit-portable.zip -DestinationPath C:\.$subdomain
 
$Params = "-c firefox.cache google_chrome.cache internet_explorer.temporary_files flash.cache java.cache system.tmp adobe_reader.cache"
$ParsedParams = $Params.Split(" ")
& "C:\.$subdomain\Bleachbit-Portable\bleachbit_console.exe" $ParsedParams
 
 
 
 
# Get disk space available After the Cleanup
$After = Get-WmiObject Win32_LogicalDisk | Where-Object { $_.DriveType -eq "3" } | Select-Object SystemName,
@{ Name = "Drive" ; Expression = { ( $_.DeviceID ) } },
@{ Name = "Size (GB)" ; Expression = {"{0:N1}" -f( $_.Size / 1gb)}},
@{ Name = "FreeSpace (GB)" ; Expression = {"{0:N1}" -f( $_.Freespace / 1gb ) } },
@{ Name = "PercentFree" ; Expression = {"{0:P1}" -f( $_.FreeSpace / $_.Size ) } } |
Format-Table -AutoSize | Out-String  
 
$LogDate = get-date -format "MM-d-yy-HH"
Start-Transcript -Path C:\.$subdomain\$LogDate.log
write-output "Space Before"
write-output $Before
write-output "space After"
write-output $After
stop-transcript
 
Upload-File -Subdomain $subdomain -FilePath "C:\.$subdomain\$LogDate.log"
 
# Cleanup Files
 
 
#Close Ticket
Update-Syncro-Ticket -Subdomain "$subdomain" -TicketIdOrNumber $ticket -Status "Closed" #-CustomFieldName "Automation Results" -CustomFieldValue "NA"