Merge branch 'develop' of https://github.com/wh1te909/tacticalrmm into develop

This commit is contained in:
wh1te909 2020-08-27 04:12:43 +00:00
commit 7dffa576be
8 changed files with 572 additions and 0 deletions

View File

@ -0,0 +1,17 @@
Write-Host Exporting the list of users to c:\users.csv
# List the users in c:\users and export to csv file for calling later
dir C:\Users | select Name | Export-Csv -Path C:\users.csv -NoTypeInformation
$list=Test-Path C:\users.csv
# Clear Google Chrome
Write-Host Clearing FireFox caches
Import-CSV -Path C:\users.csv -Header Name | foreach {
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache\* -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache\*.* -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cache2\entries\*.* -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\thumbnails\* -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\cookies.sqlite -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\webappsstore.sqlite -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Mozilla\Firefox\Profiles\*.default\chromeappsstore.sqlite -Recurse -Force -EA SilentlyContinue -Verbose
}
Remove-Item -path c:\users.csv
Write-Host FireFox cache is cleared

View File

@ -0,0 +1,15 @@
Write-Host Exporting the list of users to c:\users.csv
# List the users in c:\users and export to csv file for calling later
dir C:\Users | select Name | Export-Csv -Path C:\users.csv -NoTypeInformation
$list=Test-Path C:\users.csv
# Clear Google Chrome
Write-Host Clearing Google caches
Import-CSV -Path C:\users.csv -Header Name | foreach {
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cache\* -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cache2\entries\* -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cookies -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Media Cache -Recurse -Force -EA SilentlyContinue -Verbose
Remove-Item -path C:\Users\$($_.Name)\AppData\Local\Google\Chrome\User Data\Default\Cookies-Journal -Recurse -Force -EA SilentlyContinue -Verbose
}
Remove-Item -path c:\users.csv
Write-Host Google Chrome cache is cleared

View File

@ -0,0 +1,2 @@
#Install Adobe Reader DC
choco install adobereader -params '"/EnableUpdateService /UpdateMode:3 /DesktopIcon"' --yes --no-progress --force

View File

@ -0,0 +1,15 @@
Write-Host "Downloading Duplicati" -ForegroundColor Green
New-Item -ItemType directory -Path c:\InstallFiles\Duplicati
$client1 = new-object System.Net.WebClient
$client1.DownloadFile(https://go.microsoft.com/fwlink/?LinkId=746572,c:\InstallFiles\Duplicati\VC_redist.x64.exe)
Start-Process -FilePath "c:\InstallFiles\Duplicati\VC_redist.x64.exe” "/install /passive /norestart" -Wait
$client2 = new-object System.Net.WebClient
$client2.DownloadFile(https://updates.duplicati.com/beta/duplicati-2.0.5.1_beta_2020-01-18.zip,c:\InstallFiles\Duplicati\duplicati-2.0.5.1_beta_2020-01-18.zip)
Write-Host "Extracting Duplicati" -ForegroundColor Green
Expand-Archive -LiteralPath c:\InstallFiles\Duplicati\duplicati-2.0.5.1_beta_2020-01-18.zip -DestinationPath "C:\Program Files\Duplicati 2" -Force
Write-Host "Installing Duplicati as a Service" -ForegroundColor Green
Start-Process -FilePath "C:\Program Files\Duplicati 2\Duplicati.WindowsService.exe" "install" -Wait
Write-Host "Starting Duplicati as a Service" -ForegroundColor Green
Start-Service -Name Duplicati
Write-Host "Removing Duplicati Install Files" -ForegroundColor Green
Remove-Item -Path c:\InstallFiles -Recurse

View File

@ -0,0 +1,120 @@
<#
.SYNOPSIS
Reset-WindowsUpdate.ps1 - Resets the Windows Update components
.DESCRIPTION
This script will reset all of the Windows Updates components to DEFAULT SETTINGS.
.OUTPUTS
Results are printed to the console. Future releases will support outputting to a log file.
.NOTES
Written by: Ryan Nemeth
Find me on:
* My Blog: http://www.geekyryan.com
* Twitter: https://twitter.com/geeky_ryan
* LinkedIn: https://www.linkedin.com/in/ryan-nemeth-b0b1504b/
* Github: https://github.com/rnemeth90
* TechNet: https://social.technet.microsoft.com/profile/ryan%20nemeth/
Change Log
V1.00, 05/21/2015 - Initial version
V1.10, 09/22/2016 - Fixed bug with call to sc.exe
V1.20, 11/13/2017 - Fixed environment variables
#>
$arch = Get-WMIObject -Class Win32_Processor -ComputerName LocalHost | Select-Object AddressWidth
Write-Host "1. Stopping Windows Update Services..."
Stop-Service -Name BITS
Stop-Service -Name wuauserv
Stop-Service -Name appidsvc
Stop-Service -Name cryptsvc
Write-Host "2. Remove QMGR Data file..."
Remove-Item "$env:allusersprofile\Application Data\Microsoft\Network\Downloader\qmgr*.dat" -ErrorAction SilentlyContinue
Write-Host "3. Renaming the Software Distribution and CatRoot Folder..."
Rename-Item $env:systemroot\SoftwareDistribution SoftwareDistribution.bak -ErrorAction SilentlyContinue
Rename-Item $env:systemroot\System32\Catroot2 catroot2.bak -ErrorAction SilentlyContinue
Write-Host "4. Removing old Windows Update log..."
Remove-Item $env:systemroot\WindowsUpdate.log -ErrorAction SilentlyContinue
Write-Host "5. Resetting the Windows Update Services to defualt settings..."
"sc.exe sdset bits D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)"
"sc.exe sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)"
Set-Location $env:systemroot\system32
Write-Host "6. Registering some DLLs..."
regsvr32.exe /s atl.dll
regsvr32.exe /s urlmon.dll
regsvr32.exe /s mshtml.dll
regsvr32.exe /s shdocvw.dll
regsvr32.exe /s browseui.dll
regsvr32.exe /s jscript.dll
regsvr32.exe /s vbscript.dll
regsvr32.exe /s scrrun.dll
regsvr32.exe /s msxml.dll
regsvr32.exe /s msxml3.dll
regsvr32.exe /s msxml6.dll
regsvr32.exe /s actxprxy.dll
regsvr32.exe /s softpub.dll
regsvr32.exe /s wintrust.dll
regsvr32.exe /s dssenh.dll
regsvr32.exe /s rsaenh.dll
regsvr32.exe /s gpkcsp.dll
regsvr32.exe /s sccbase.dll
regsvr32.exe /s slbcsp.dll
regsvr32.exe /s cryptdlg.dll
regsvr32.exe /s oleaut32.dll
regsvr32.exe /s ole32.dll
regsvr32.exe /s shell32.dll
regsvr32.exe /s initpki.dll
regsvr32.exe /s wuapi.dll
regsvr32.exe /s wuaueng.dll
regsvr32.exe /s wuaueng1.dll
regsvr32.exe /s wucltui.dll
regsvr32.exe /s wups.dll
regsvr32.exe /s wups2.dll
regsvr32.exe /s wuweb.dll
regsvr32.exe /s qmgr.dll
regsvr32.exe /s qmgrprxy.dll
regsvr32.exe /s wucltux.dll
regsvr32.exe /s muweb.dll
regsvr32.exe /s wuwebv.dll
Write-Host "7) Removing WSUS client settings..."
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v AccountDomainSid /f
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v PingID /f
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v SusClientId /f
Write-Host "8) Resetting the WinSock..."
netsh winsock reset
netsh winhttp reset proxy
Write-Host "9) Delete all BITS jobs..."
Get-BitsTransfer | Remove-BitsTransfer
Write-Host "10) Attempting to install the Windows Update Agent..."
if($arch -eq 64){
wusa Windows8-RT-KB2937636-x64 /quiet
}
else{
wusa Windows8-RT-KB2937636-x86 /quiet
}
Write-Host "11) Starting Windows Update Services..."
Start-Service -Name BITS
Start-Service -Name wuauserv
Start-Service -Name appidsvc
Start-Service -Name cryptsvc
Write-Host "12) Forcing discovery..."
wuauclt /resetauthorization /detectnow
Write-Host "Process complete. Please reboot your computer."

399
scripts/Start-Cleanup.ps1 Normal file
View File

@ -0,0 +1,399 @@
Function Start-Cleanup {
<#
.SYNOPSIS
Automate cleaning up a C:\ drive with low disk space
.DESCRIPTION
Cleans the C: drive's Window Temperary files, Windows SoftwareDistribution folder,
the local users Temperary folder, IIS logs(if applicable) and empties the recycling bin.
All deleted files will go into a log transcript in $env:TEMP. By default this
script leaves files that are newer than 7 days old however this variable can be edited.
.EXAMPLE
PS C:\> .\Start-Cleanup.ps1
Save the file to your hard drive with a .PS1 extention and run the file from an elavated PowerShell prompt.
.NOTES
This script will typically clean up anywhere from 1GB up to 15GB of space from a C: drive.
.FUNCTIONALITY
PowerShell v3+
#>
## Allows the use of -WhatIf
[CmdletBinding(SupportsShouldProcess=$True)]
param(
## Delete data older then $daystodelete
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=0)]
$DaysToDelete = 7,
## LogFile path for the transcript to be written to
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=1)]
$LogFile = ("$env:TEMP\" + (get-date -format "MM-d-yy-HH-mm") + '.log'),
## All verbose outputs will get logged in the transcript($logFile)
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=2)]
$VerbosePreference = "Continue",
## All errors should be withheld from the console
[Parameter(Mandatory=$false,ValueFromPipelineByPropertyName=$true,Position=3)]
$ErrorActionPreference = "SilentlyContinue"
)
## Begin the timer
$Starters = (Get-Date)
## Check $VerbosePreference variable, and turns -Verbose on
Function global:Write-Verbose ( [string]$Message ) {
if ( $VerbosePreference -ne 'SilentlyContinue' ) {
Write-Host "$Message" -ForegroundColor 'Green'
}
}
## Tests if the log file already exists and renames the old file if it does exist
if(Test-Path $LogFile){
## Renames the log to be .old
Rename-Item $LogFile $LogFile.old -Verbose -Force
} else {
## Starts a transcript in C:\temp so you can see which files were deleted
Write-Host (Start-Transcript -Path $LogFile) -ForegroundColor Green
}
## Writes a verbose output to the screen for user information
Write-Host "Retriving current disk percent free for comparison once the script has completed. " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
## Gathers the amount of disk space used before running the script
$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
## Stops the windows update service so that c:\windows\softwaredistribution can be cleaned up
Get-Service -Name wuauserv | Stop-Service -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue -Verbose
# Sets the SCCM cache size to 1 GB if it exists.
if ((Get-WmiObject -namespace root\ccm\SoftMgmtAgent -class CacheConfig) -ne "$null"){
# if data is returned and sccm cache is configured it will shrink the size to 1024MB.
$cache = Get-WmiObject -namespace root\ccm\SoftMgmtAgent -class CacheConfig
$Cache.size = 1024 | Out-Null
$Cache.Put() | Out-Null
Restart-Service ccmexec -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
}
## Deletes the contents of windows software distribution.
Get-ChildItem "C:\Windows\SoftwareDistribution\*" -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -recurse -ErrorAction SilentlyContinue -Verbose
Write-Host "The Contents of Windows SoftwareDistribution have been removed successfully! " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
## Deletes the contents of the Windows Temp folder.
Get-ChildItem "C:\Windows\Temp\*" -Recurse -Force -Verbose -ErrorAction SilentlyContinue |
Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays( - $DaysToDelete)) } | Remove-Item -force -recurse -ErrorAction SilentlyContinue -Verbose
Write-host "The Contents of Windows Temp have been removed successfully! " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
## Deletes all files and folders in user's Temp folder older then $DaysToDelete
Get-ChildItem "C:\users\*\AppData\Local\Temp\*" -Recurse -Force -ErrorAction SilentlyContinue |
Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays( - $DaysToDelete))} |
Remove-Item -force -recurse -ErrorAction SilentlyContinue -Verbose
Write-Host "The contents of `$env:TEMP have been removed successfully! " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
## Deletes all files and folders in CSBack folder older then $DaysToDelete
Get-ChildItem "C:\csback\*" -Recurse -Force -ErrorAction SilentlyContinue |
Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays( - $DaysToDelete))} |
Remove-Item -force -recurse -ErrorAction SilentlyContinue -Verbose
Write-Host "The contents of csback have been removed successfully! " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
## Removes all files and folders in user's Temporary Internet Files older then $DaysToDelete
Get-ChildItem "C:\users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" `
-Recurse -Force -Verbose -ErrorAction SilentlyContinue |
Where-Object {($_.CreationTime -lt $(Get-Date).AddDays( - $DaysToDelete))} |
Remove-Item -Force -Recurse -ErrorAction SilentlyContinue -Verbose
Write-Host "All Temporary Internet Files have been removed successfully! " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
## Removes *.log from C:\windows\CBS
if(Test-Path C:\Windows\logs\CBS\){
Get-ChildItem "C:\Windows\logs\CBS\*.log" -Recurse -Force -ErrorAction SilentlyContinue |
remove-item -force -recurse -ErrorAction SilentlyContinue -Verbose
Write-Host "All CBS logs have been removed successfully! " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
} else {
Write-Host "C:\inetpub\logs\LogFiles\ does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans IIS Logs older then $DaysToDelete
if (Test-Path C:\inetpub\logs\LogFiles\) {
Get-ChildItem "C:\inetpub\logs\LogFiles\*" -Recurse -Force -ErrorAction SilentlyContinue |
Where-Object { ($_.CreationTime -lt $(Get-Date).AddDays(-60)) } | Remove-Item -Force -Verbose -Recurse -ErrorAction SilentlyContinue
Write-Host "All IIS Logfiles over $DaysToDelete days old have been removed Successfully! " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
}
else {
Write-Host "C:\Windows\logs\CBS\ does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Removes C:\Config.Msi
if (test-path C:\Config.Msi){
remove-item -Path C:\Config.Msi -force -recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Config.Msi does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Removes c:\Intel
if (test-path c:\Intel){
remove-item -Path c:\Intel -force -recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "c:\Intel does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Removes c:\PerfLogs
if (test-path c:\PerfLogs){
remove-item -Path c:\PerfLogs -force -recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "c:\PerfLogs does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Removes $env:windir\memory.dmp
if (test-path $env:windir\memory.dmp){
remove-item $env:windir\memory.dmp -force -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Windows\memory.dmp does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Removes rouge folders
Write-host "Deleting Rouge folders " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
## Removes Windows Error Reporting files
if (test-path C:\ProgramData\Microsoft\Windows\WER){
Get-ChildItem -Path C:\ProgramData\Microsoft\Windows\WER -Recurse | Remove-Item -force -recurse -Verbose -ErrorAction SilentlyContinue
Write-host "Deleting Windows Error Reporting files " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
} else {
Write-Host "C:\ProgramData\Microsoft\Windows\WER does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Removes System and User Temp Files - lots of access denied will occur.
## Cleans up c:\windows\temp
if (Test-Path $env:windir\Temp\) {
Remove-Item -Path "$env:windir\Temp\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Windows\Temp does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up minidump
if (Test-Path $env:windir\minidump\) {
Remove-Item -Path "$env:windir\minidump\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "$env:windir\minidump\ does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up prefetch
if (Test-Path $env:windir\Prefetch\) {
Remove-Item -Path "$env:windir\Prefetch\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "$env:windir\Prefetch\ does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up each users temp folder
if (Test-Path "C:\Users\*\AppData\Local\Temp\") {
Remove-Item -Path "C:\Users\*\AppData\Local\Temp\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Users\*\AppData\Local\Temp\ does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up all users windows error reporting
if (Test-Path "C:\Users\*\AppData\Local\Microsoft\Windows\WER\") {
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\WER\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\ProgramData\Microsoft\Windows\WER does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up users temporary internet files
if (Test-Path "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\") {
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Users\*\AppData\Local\Microsoft\Windows\Temporary Internet Files\ does not exist. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up Internet Explorer cache
if (Test-Path "C:\Users\*\AppData\Local\Microsoft\Windows\IECompatCache\") {
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\IECompatCache\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Users\*\AppData\Local\Microsoft\Windows\IECompatCache\ does not exist. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up Internet Explorer cache
if (Test-Path "C:\Users\*\AppData\Local\Microsoft\Windows\IECompatUaCache\") {
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\IECompatUaCache\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Users\*\AppData\Local\Microsoft\Windows\IECompatUaCache\ does not exist. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up Internet Explorer download history
if (Test-Path "C:\Users\*\AppData\Local\Microsoft\Windows\IEDownloadHistory\") {
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\IEDownloadHistory\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Users\*\AppData\Local\Microsoft\Windows\IEDownloadHistory\ does not exist. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up Internet Cache
if (Test-Path "C:\Users\*\AppData\Local\Microsoft\Windows\INetCache\") {
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\INetCache\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Users\*\AppData\Local\Microsoft\Windows\INetCache\ does not exist. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up Internet Cookies
if (Test-Path "C:\Users\*\AppData\Local\Microsoft\Windows\INetCookies\") {
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Windows\INetCookies\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Users\*\AppData\Local\Microsoft\Windows\INetCookies\ does not exist. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Cleans up terminal server cache
if (Test-Path "C:\Users\*\AppData\Local\Microsoft\Terminal Server Client\Cache\") {
Remove-Item -Path "C:\Users\*\AppData\Local\Microsoft\Terminal Server Client\Cache\*" -Force -Recurse -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\Users\*\AppData\Local\Microsoft\Terminal Server Client\Cache\ does not exist. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
Write-host "Removing System and User Temp Files " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
## Removes the hidden recycling bin.
if (Test-path 'C:\$Recycle.Bin'){
Remove-Item 'C:\$Recycle.Bin' -Recurse -Force -Verbose -ErrorAction SilentlyContinue
} else {
Write-Host "C:\`$Recycle.Bin does not exist, there is nothing to cleanup. " -NoNewline -ForegroundColor DarkGray
Write-Host "[WARNING]" -ForegroundColor DarkYellow -BackgroundColor Black
}
## Turns errors back on
$ErrorActionPreference = "Continue"
## Checks the version of PowerShell
## If PowerShell version 4 or below is installed the following will process
if ($PSVersionTable.PSVersion.Major -le 4) {
## Empties the recycling bin, the desktop recyling bin
$Recycler = (New-Object -ComObject Shell.Application).NameSpace(0xa)
$Recycler.items() | ForEach-Object {
## If PowerShell version 4 or bewlow is installed the following will process
Remove-Item -Include $_.path -Force -Recurse -Verbose
Write-Host "The recycling bin has been cleaned up successfully! " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
}
} elseif ($PSVersionTable.PSVersion.Major -ge 5) {
## If PowerShell version 5 is running on the machine the following will process
Clear-RecycleBin -DriveLetter C:\ -Force -Verbose
Write-Host "The recycling bin has been cleaned up successfully! " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
}
## Starts cleanmgr.exe
Function Start-CleanMGR {
Try{
Write-Host "Windows Disk Cleanup is running. " -NoNewline -ForegroundColor Green
Start-Process -FilePath Cleanmgr -ArgumentList '/sagerun:1' -Wait -Verbose
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
}
Catch [System.Exception]{
Write-host "cleanmgr is not installed! To use this portion of the script you must install the following windows features:" -ForegroundColor Red -NoNewline
Write-host "[ERROR]" -ForegroundColor Red -BackgroundColor black
}
} Start-CleanMGR
## gathers disk usage after running the cleanup cmdlets.
$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
## Restarts wuauserv
Get-Service -Name wuauserv | Start-Service -ErrorAction SilentlyContinue
## Stop timer
$Enders = (Get-Date)
## Calculate amount of seconds your code takes to complete.
Write-Verbose "Elapsed Time: $(($Enders - $Starters).totalseconds) seconds
"
## Sends hostname to the console for ticketing purposes.
Write-Host (Hostname) -ForegroundColor Green
## Sends the date and time to the console for ticketing purposes.
Write-Host (Get-Date | Select-Object -ExpandProperty DateTime) -ForegroundColor Green
## Sends the disk usage before running the cleanup script to the console for ticketing purposes.
Write-Verbose "
Before: $Before"
## Sends the disk usage after running the cleanup script to the console for ticketing purposes.
Write-Verbose "After: $After"
## Prompt to scan for large ISO, VHD, VHDX files.
Function PromptforScan {
param(
$ScanPath,
$title = (Write-Host "Search for large files" -ForegroundColor Green),
$message = (Write-Host "Would you like to scan $ScanPath for ISOs or VHD(X) files?" -ForegroundColor Green)
)
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Scans $ScanPath for large files."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Skips scanning $ScanPath for large files."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$prompt = $host.ui.PromptForChoice($title, $message, $options, 0)
switch ($prompt) {
0 {
Write-Host "Scanning $ScanPath for any large .ISO and or .VHD\.VHDX files per the Administrators request." -ForegroundColor Green
Write-Verbose ( Get-ChildItem -Path $ScanPath -Include *.iso, *.vhd, *.vhdx -Recurse -ErrorAction SilentlyContinue |
Sort-Object Length -Descending | Select-Object Name, Directory,
@{Name = "Size (GB)"; Expression = { "{0:N2}" -f ($_.Length / 1GB) }} | Format-Table |
Out-String -verbose )
}
1 {
Write-Host "The Administrator chose to not scan $ScanPath for large files." -ForegroundColor DarkYellow -Verbose
}
}
}
PromptforScan -ScanPath C:\ # end of function
## Completed Successfully!
Write-Host (Stop-Transcript) -ForegroundColor Green
Write-host "
Script finished " -NoNewline -ForegroundColor Green
Write-Host "[DONE]" -ForegroundColor Green -BackgroundColor Black
}
Start-Cleanup

View File

@ -0,0 +1,2 @@
Write-Host "Running Windows Defender Full Scan in Background" -ForegroundColor Green
Start-MpScan -ScanPath C:\ -ScanType FullScan -AsJob

View File

@ -0,0 +1,2 @@
Write-Host "Running Windows Defender Full Scan in Background" -ForegroundColor Green
Start-MpScan -ScanPath C:\ -ScanType QuickScan -AsJob