From 84b08e5abeb529e0b68a03d14d9de9b954bfa4d8 Mon Sep 17 00:00:00 2001 From: aaron Date: Mon, 18 Dec 2023 18:01:19 +0000 Subject: [PATCH] Upload files to "/" --- Enable-VSSScheduledTasks.ps1 | 68 ++++++++++++++++++++++++++++++++++++ Fix-FileSystem.ps1 | 7 ++++ Fix-NoTaskbar.bat | 4 +++ Get-InstalledPrograms.ps1 | 3 ++ Get-OSTFileSize.ps1 | 26 ++++++++++++++ 5 files changed, 108 insertions(+) create mode 100644 Enable-VSSScheduledTasks.ps1 create mode 100644 Fix-FileSystem.ps1 create mode 100644 Fix-NoTaskbar.bat create mode 100644 Get-InstalledPrograms.ps1 create mode 100644 Get-OSTFileSize.ps1 diff --git a/Enable-VSSScheduledTasks.ps1 b/Enable-VSSScheduledTasks.ps1 new file mode 100644 index 0000000..69aeacb --- /dev/null +++ b/Enable-VSSScheduledTasks.ps1 @@ -0,0 +1,68 @@ +#Script to Enable Volume Shadow Copies with Custom Schedule, and disable any Default VSS tasks if there are any. + +#Setting Variables +$logPath = "C:\Logs" +$date = Get-Date -Format yyyy-MM-dd +$ScheduledTasks = @() +$DisabledTasks = @() + +New-Item -ItemType Directory -Force -Path $logPath + +#Enable VSS and Set tasks +$Disks = Get-Volume | Where-Object {$_.DriveType -eq "Fixed"} | Where-Object {$_.DriveLetter -ne $null} | Where-Object {$_.Size -gt 5GB} + +$offset = New-TimeSpan +$offsetInterval = New-TimeSpan -Minutes 15 + +foreach ($Disk in $Disks) { + # Enable Shadows + vssadmin add shadowstorage /for=$($Disk.DriveLetter): /on=$($Disk.DriveLetter): /maxsize=10% + # Set Shadow Copy Scheduled Task for C: 06:00, 12:00 and 17:00 + + $time1 = New-TimeSpan -Hours 6 + $time2 = New-TimeSpan -Hours 12 + $time3 = New-TimeSpan -Hours 17 + + $Argument = "-command ""C:\Windows\system32\vssadmin.exe create shadow /for=$($Disk.DriveLetter):""" + $Action = new-scheduledtaskaction -execute "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Argument $Argument + $Trigger1 = new-scheduledtasktrigger -daily -at ($time1 + $offset).ToString() + $Trigger2 = new-scheduledtasktrigger -daily -at ($time2 + $offset).ToString() + $Trigger3 = new-scheduledtasktrigger -daily -at ($time3 + $offset).ToString() + Register-ScheduledTask -TaskName "ShadowCopy $($Disk.DriveLetter) drive" -Trigger $Trigger1,$Trigger2,$Trigger3 -Action $Action -Description "ShadowCopy for $($Disk.DriveLetter) drive" -user "NT AUTHORITY\SYSTEM" -RunLevel Highest -Force + $offset = $offset + $offsetInterval +} + +#Disable Default tasks +$ScheduledTasks = Get-ScheduledTask -TaskName "ShadowCopyVolume{*}" + +$DisabledTasks = foreach ($Task in $ScheduledTasks){Disable-ScheduledTask -TaskName $Task.TaskName} + +$DisabledTasks | ConvertTo-html -Property TaskName, State | Out-File "$logPath\$date-Shadows.html" + +if (!$DisabledTasks) {Write-Host "No Default VSS Tasks Disabled"} +else {Write-Host "Default VSS Tasks have been disabled. Please see the log on Device to see details: C:\DiscStuff\Logs"} + +#Update Custom fields +$ScheduledTasks = Get-ScheduledTask -TaskName "ShadowCopy*" +$DefaultTasks = Get-ScheduledTask -TaskName "ShadowCopyVolume{*}" +$CustomTasks = Get-ScheduledTask -TaskName "ShadowCopy * drive" + +$VSS = [PSCustomObject]@{ + enabled = $false + type = $null +} +#No Tasks +if ($ScheduledTasks -eq $null) + {Write-Host "No VSS Tasks"} +#Default Tasks +elseif ($DefaultTasks.State -ne "Disabled") + {Write-Host "Default VSS Tasks Enabled"; $VSS.enabled = $true; $VSS.type = "Default"} +#Default Tasks Disabled and No Custom Tasks +if (($DefaultTasks.State -eq "Disabled") -and ($CustomTasks -eq $null)) + {Write-Host "Default VSS Tasks Disabled and NO Custom VSS Tasks"; $VSS.enabled = $false; $VSS.type = "Default"} +#Default Tasks Disabled and Custom Tasks Enabled +if ((($DefaultTasks.State -eq "Disabled") -or ($DefaultTasks -eq $null)) -and ($CustomTasks -ne $null)) + {Write-Host "Default VSS Tasks Disabled and Custom VSS Tasks Enabled"; $VSS.enabled = $true; $VSS.type = "Custom"} + +if ($Host.Version.Major -gt 4){Write-Host $VSS} +elseif ($Host.Version.Major -lt 5){$VSS} diff --git a/Fix-FileSystem.ps1 b/Fix-FileSystem.ps1 new file mode 100644 index 0000000..93b87e6 --- /dev/null +++ b/Fix-FileSystem.ps1 @@ -0,0 +1,7 @@ +# Runs the sfc and dism commands to fix any issues with a file system + +sfc /scannow +dism /online /cleanup-image /CheckHealth +dism /online /cleanup-image /ScanHealth +dism /online /cleanup-image /startcomponentcleanup +dism /online /cleanup-image /restorehealth diff --git a/Fix-NoTaskbar.bat b/Fix-NoTaskbar.bat new file mode 100644 index 0000000..cb081db --- /dev/null +++ b/Fix-NoTaskbar.bat @@ -0,0 +1,4 @@ +# Force restarts Windows File Explorer to fix a bug where the task bar is missing. + +taskkill /f /im explorer.exe +explorer.exe diff --git a/Get-InstalledPrograms.ps1 b/Get-InstalledPrograms.ps1 new file mode 100644 index 0000000..6f1275f --- /dev/null +++ b/Get-InstalledPrograms.ps1 @@ -0,0 +1,3 @@ +# Gets a list of installed programs + + Get-WmiObject -Class Win32_Product -Property Name | Select-Object name diff --git a/Get-OSTFileSize.ps1 b/Get-OSTFileSize.ps1 new file mode 100644 index 0000000..3758938 --- /dev/null +++ b/Get-OSTFileSize.ps1 @@ -0,0 +1,26 @@ +# Generates a list of all user's OST file sizes + +$UserFolder = "C:\Users" +$OutlookFolder = "AppData\Local\Microsoft\Outlook" + +class OST { + [string]$name + [float]$size +} + +Get-ChildItem -Path $UserFolder | ForEach-Object { + $User = $_ + $Folder = "$User\$OutlookFolder" + if ($(Test-Path -Path $Folder)){ + $FoundFiles = Get-ChildItem $Folder -Filter *.ost | Where-Object {$_.Length / 1GB -gt 1} + $FoundFiles | Select-Object FullName, Length | ForEach-Object { + $Name = $_.FullName + $Size = [Math]::Round(($_.Length / 1GB), 2) + $ost = [OST]::new() + $ost.name = $Name + $ost.size = $Size + } + } +} + +$ost