Guest User

code library

a guest
Jan 26th, 2026
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.09 KB | None | 0 0
  1. # general tool creation begins
  2. $global:DriveLabel
  3. $global:DriveLetter
  4. $global:OriginDriveLabel # default drive for all jobs
  5. $global:OriginDriveLetter # default drive for all jobs
  6. $global:JobType
  7.  
  8.  
  9.  
  10. $LogoSplat =@{
  11. AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
  12. }
  13.  
  14. $PrioritySplat =@{
  15. AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
  16. Sound = 'SMS'
  17. }
  18.  
  19. # These splats need to be updated when used (Get-UpdatedSplats handles this) - Start
  20.  
  21. $ResolutionToastSplat =@{
  22. AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
  23. Text = "`n$DriveLabel resolved as $DriveLetter"
  24. } # creating a notification to tell you about the drive label Resolution
  25.  
  26. $OriginResolutionToastSplat =@{
  27. AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
  28. Text = "`n$OriginDriveLabel resolved as $OriginDriveLetter"
  29. } # creating a notification to tell you about the origin drive label Resolution
  30.  
  31. $BackupProgressToastSplat =@{
  32. AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
  33. Header = (New-BTHeader -Title "$JobType in progress")
  34. Text = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter) to $DriveLabel ($DriveLetter)"
  35.  
  36. }
  37.  
  38. $ChkdskProgressToastSplat =@{
  39. AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
  40. Header = (New-BTHeader -Title "$JobType in progress")
  41. Text = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter)"
  42.  
  43. }
  44.  
  45. $TestProgressToastSplat =@{
  46. AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
  47. Header = (New-BTHeader -Title "$JobType in progress")
  48. Text = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter) to $DriveLabel ($DriveLetter) - (Not really)"
  49.  
  50. }
  51.  
  52. $GenericHeaderToastSplat =@{
  53. AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
  54. Header = (New-BTHeader -Title "$JobType in progress")
  55. } # This is used when custom text is needed as PS gets confused by Text being used twice
  56.  
  57. # These splats need to be updated when used (Get-UpdatedSplats handles this) - End
  58.  
  59. function Write-Resolution {Write-Output "`n$DriveLabel Resolved as $DriveLetter"} # Writing the drive Resolution to console
  60. function Write-OriginResolution {Write-Output "`n$OriginDriveLabel Resolved as $OriginDriveLetter"} # Writing the drive Resolution to console
  61. function Write-ModularLog {Start-Transcript -Path "C:\Users\Redacted\Documents\DISM & SFC logs\$OriginDriveLabel $JobType Log $(get-date -f dd-MM-yyyy).txt"} # Creating a log
  62. function Get-DriveLetter {
  63. if($JobType -eq "Backup")
  64. {(Get-WmiObject Win32_LogicalDisk | Where { $_.VolumeName -eq $DriveLabel }).DeviceID}
  65. }# Retrieving the volume label for this job
  66. function Get-OriginDriveLetter {(Get-WmiObject Win32_LogicalDisk | Where { $_.VolumeName -eq $OriginDriveLabel }).DeviceID} # Retrieving the volume label for this job
  67. function Get-UpdatedSplats {
  68. $ResolutionToastSplat["Text"] = "`n$DriveLabel Resolved as $DriveLetter"
  69. $OriginResolutionToastSplat["Text"] = "`n$OriginDriveLabel Resolved as $OriginDriveLetter"
  70. $BackupProgressToastSplat["Text"] = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter) to $DriveLabel ($DriveLetter)"
  71. $BackupProgressToastSplat["Header"] = (New-BTHeader -Title "$JobType in progress")
  72. $ChkdskProgressToastSplat["Text"] = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter)"
  73. $ChkdskProgressToastSplat["Header"] = (New-BTHeader -Title "$JobType in progress")
  74. $TestProgressToastSplat["Text"] = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter) to $DriveLabel ($DriveLetter) - (Not really)"
  75. $TestProgressToastSplat["Header"] = (New-BTHeader -Title "$JobType in progress")
  76. $GenericHeaderToastSplat["Header"] = (New-BTHeader -Title "$JobType in progress")
  77. } #updates splats with hash tables, as these do not update themselves once instantiated
  78.  
  79.  
  80. function Add-ProgressToastSplat {
  81. if("Backup" -eq $JobType)
  82. {New-BurntToastNotification @BackupProgressToastSplat}
  83. if("Chkdsk" -eq $JobType)
  84. {New-BurntToastNotification @ChkdskProgressToastSplat}
  85. if("Test" -eq $JobType)
  86. {New-BurntToastNotification @TestProgressToastSplat}} # not being used :(
  87.  
  88. function Write-DriveResolutionAlerts {Write-OriginResolution
  89. New-BurntToastNotification @OriginResolutionToastSplat
  90. Start-Sleep -Seconds 10
  91.  
  92. if ("Backup" -eq $JobType) {Write-Resolution
  93. New-BurntToastNotification @ResolutionToastSplat
  94. Start-Sleep -Seconds 10 }
  95.  
  96. if ("Test" -eq $JobType) {Write-Resolution
  97. New-BurntToastNotification @ResolutionToastSplat
  98. Start-Sleep -Seconds 10 }
  99.  
  100. New-BurntToastNotification @PrioritySplat -Text "If drive resolutions are not correct, you have 10 seconds to close this window"
  101. Start-Sleep -Seconds 10}
  102.  
  103. function Start-ChkdskCommand {echo y | chkdsk $OriginDriveLetter /r /x}
  104.  
  105. function Start-ChkdskDriveChangeJobs {
  106. Write-Output "`nEnding log for this drive - There should be further logs"
  107. Stop-Transcript
  108. $OriginDriveLetter = Get-OriginDriveLetter
  109. Get-UpdatedSplats
  110. Write-ModularLog
  111. Write-DriveResolutionAlerts
  112. ChkdskCommand}
  113.  
  114.  
  115. function Start-ScriptedStart
  116. {
  117.  
  118. $OriginDriveLetter=Get-OriginDriveLetter
  119. $DriveLetter=Get-DriveLetter
  120.  
  121. Get-UpdatedSplats
  122.  
  123. Write-ModularLog
  124.  
  125. Write-DriveResolutionAlerts
  126.  
  127. New-BurntToastNotification @LogoSplat -Text "Initiating $JobType"
  128. Start-Sleep -Seconds 10
  129. }
  130.  
  131. function Start-UnattendedPowerPlanEnable
  132. {
  133. New-BurntToastNotification @LogoSplat -Text "Setting Powerplan to High Performance"
  134. Write-Output "Setting Powerplan to High Performance"
  135.  
  136. powercfg /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
  137.  
  138. Start-Sleep -Seconds 10
  139.  
  140.  
  141. New-BurntToastNotification @GenericHeaderToastSplat -Text "Running $JobType in 30 seconds - DO NOT TURN OFF YOUR COMPUTER!"
  142.  
  143. Start-Sleep -Seconds 10
  144.  
  145. New-BurntToastNotification @GenericHeaderToastSplat -Text "If you need to shutdown, set power plan to Out of Office Hours & put it to sleep"
  146.  
  147. Start-Sleep -Seconds 10
  148. }
  149.  
  150. function Start-UnattendedPowerPlanDisable
  151. {
  152. New-BurntToastNotification @LogoSplat -Text "Returning Powerplan to Out of Office Hours"
  153. Write-Output "Returning Powerplan to Out of Office Hours"
  154. powercfg /setactive c965af8e-2c48-4aa7-81b2-5c1814eeb79b
  155. Start-Sleep -Seconds 15
  156. }
  157.  
  158. function Start-InstanceCheckandShutdown
  159. {
  160.  
  161. if(((get-process -name PowerShell -erroraction ignore) -eq $null -ne $PID))
  162. {
  163. Start-UnattendedPowerPlanDisable
  164. write-output "`nEntering Hibernation in 60 seconds - close window to avoid"
  165. Stop-Transcript
  166. New-BurntToastNotification @PrioritySplat -Text "Entering Hibernation in 60 seconds - close window to avoid"
  167.  
  168. Start-Sleep -Seconds 60
  169.  
  170. shutdown /h
  171. }
  172. else {
  173.  
  174. Do
  175. {
  176. Write-Output "Waiting for Other PS Instance to close..."
  177. start-sleep -Second 15
  178. }
  179. Until ((get-process -name PowerShell -erroraction ignore) -eq $null -ne $PID)
  180.  
  181. Start-UnattendedPowerPlanDisable
  182.  
  183. write-output "`nEntering Hibernation in 60 seconds - close window to avoid"
  184. Stop-Transcript
  185.  
  186. New-BurntToastNotification @PrioritySplat -Text "Entering Hibernation in 60 seconds - close window to avoid"
  187.  
  188. Start-Sleep -Seconds 60
  189.  
  190. shutdown /h
  191.  
  192. }
  193. }
  194.  
  195.  
Advertisement
Add Comment
Please, Sign In to add comment