Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # general tool creation begins
- $global:DriveLabel
- $global:DriveLetter
- $global:OriginDriveLabel # default drive for all jobs
- $global:OriginDriveLetter # default drive for all jobs
- $global:JobType
- $LogoSplat =@{
- AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
- }
- $PrioritySplat =@{
- AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
- Sound = 'SMS'
- }
- # These splats need to be updated when used (Get-UpdatedSplats handles this) - Start
- $ResolutionToastSplat =@{
- AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
- Text = "`n$DriveLabel resolved as $DriveLetter"
- } # creating a notification to tell you about the drive label Resolution
- $OriginResolutionToastSplat =@{
- AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
- Text = "`n$OriginDriveLabel resolved as $OriginDriveLetter"
- } # creating a notification to tell you about the origin drive label Resolution
- $BackupProgressToastSplat =@{
- AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
- Header = (New-BTHeader -Title "$JobType in progress")
- Text = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter) to $DriveLabel ($DriveLetter)"
- }
- $ChkdskProgressToastSplat =@{
- AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
- Header = (New-BTHeader -Title "$JobType in progress")
- Text = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter)"
- }
- $TestProgressToastSplat =@{
- AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
- Header = (New-BTHeader -Title "$JobType in progress")
- Text = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter) to $DriveLabel ($DriveLetter) - (Not really)"
- }
- $GenericHeaderToastSplat =@{
- AppLogo = "C:\Users\Redacted\Documents\DISM & SFC logs\Resources\spanner.jpg"
- Header = (New-BTHeader -Title "$JobType in progress")
- } # This is used when custom text is needed as PS gets confused by Text being used twice
- # These splats need to be updated when used (Get-UpdatedSplats handles this) - End
- function Write-Resolution {Write-Output "`n$DriveLabel Resolved as $DriveLetter"} # Writing the drive Resolution to console
- function Write-OriginResolution {Write-Output "`n$OriginDriveLabel Resolved as $OriginDriveLetter"} # Writing the drive Resolution to console
- 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
- function Get-DriveLetter {
- if($JobType -eq "Backup")
- {(Get-WmiObject Win32_LogicalDisk | Where { $_.VolumeName -eq $DriveLabel }).DeviceID}
- }# Retrieving the volume label for this job
- function Get-OriginDriveLetter {(Get-WmiObject Win32_LogicalDisk | Where { $_.VolumeName -eq $OriginDriveLabel }).DeviceID} # Retrieving the volume label for this job
- function Get-UpdatedSplats {
- $ResolutionToastSplat["Text"] = "`n$DriveLabel Resolved as $DriveLetter"
- $OriginResolutionToastSplat["Text"] = "`n$OriginDriveLabel Resolved as $OriginDriveLetter"
- $BackupProgressToastSplat["Text"] = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter) to $DriveLabel ($DriveLetter)"
- $BackupProgressToastSplat["Header"] = (New-BTHeader -Title "$JobType in progress")
- $ChkdskProgressToastSplat["Text"] = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter)"
- $ChkdskProgressToastSplat["Header"] = (New-BTHeader -Title "$JobType in progress")
- $TestProgressToastSplat["Text"] = "Running $JobType - $OriginDriveLabel ($OriginDriveLetter) to $DriveLabel ($DriveLetter) - (Not really)"
- $TestProgressToastSplat["Header"] = (New-BTHeader -Title "$JobType in progress")
- $GenericHeaderToastSplat["Header"] = (New-BTHeader -Title "$JobType in progress")
- } #updates splats with hash tables, as these do not update themselves once instantiated
- function Add-ProgressToastSplat {
- if("Backup" -eq $JobType)
- {New-BurntToastNotification @BackupProgressToastSplat}
- if("Chkdsk" -eq $JobType)
- {New-BurntToastNotification @ChkdskProgressToastSplat}
- if("Test" -eq $JobType)
- {New-BurntToastNotification @TestProgressToastSplat}} # not being used :(
- function Write-DriveResolutionAlerts {Write-OriginResolution
- New-BurntToastNotification @OriginResolutionToastSplat
- Start-Sleep -Seconds 10
- if ("Backup" -eq $JobType) {Write-Resolution
- New-BurntToastNotification @ResolutionToastSplat
- Start-Sleep -Seconds 10 }
- if ("Test" -eq $JobType) {Write-Resolution
- New-BurntToastNotification @ResolutionToastSplat
- Start-Sleep -Seconds 10 }
- New-BurntToastNotification @PrioritySplat -Text "If drive resolutions are not correct, you have 10 seconds to close this window"
- Start-Sleep -Seconds 10}
- function Start-ChkdskCommand {echo y | chkdsk $OriginDriveLetter /r /x}
- function Start-ChkdskDriveChangeJobs {
- Write-Output "`nEnding log for this drive - There should be further logs"
- Stop-Transcript
- $OriginDriveLetter = Get-OriginDriveLetter
- Get-UpdatedSplats
- Write-ModularLog
- Write-DriveResolutionAlerts
- ChkdskCommand}
- function Start-ScriptedStart
- {
- $OriginDriveLetter=Get-OriginDriveLetter
- $DriveLetter=Get-DriveLetter
- Get-UpdatedSplats
- Write-ModularLog
- Write-DriveResolutionAlerts
- New-BurntToastNotification @LogoSplat -Text "Initiating $JobType"
- Start-Sleep -Seconds 10
- }
- function Start-UnattendedPowerPlanEnable
- {
- New-BurntToastNotification @LogoSplat -Text "Setting Powerplan to High Performance"
- Write-Output "Setting Powerplan to High Performance"
- powercfg /setactive 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c
- Start-Sleep -Seconds 10
- New-BurntToastNotification @GenericHeaderToastSplat -Text "Running $JobType in 30 seconds - DO NOT TURN OFF YOUR COMPUTER!"
- Start-Sleep -Seconds 10
- New-BurntToastNotification @GenericHeaderToastSplat -Text "If you need to shutdown, set power plan to Out of Office Hours & put it to sleep"
- Start-Sleep -Seconds 10
- }
- function Start-UnattendedPowerPlanDisable
- {
- New-BurntToastNotification @LogoSplat -Text "Returning Powerplan to Out of Office Hours"
- Write-Output "Returning Powerplan to Out of Office Hours"
- powercfg /setactive c965af8e-2c48-4aa7-81b2-5c1814eeb79b
- Start-Sleep -Seconds 15
- }
- function Start-InstanceCheckandShutdown
- {
- if(((get-process -name PowerShell -erroraction ignore) -eq $null -ne $PID))
- {
- Start-UnattendedPowerPlanDisable
- write-output "`nEntering Hibernation in 60 seconds - close window to avoid"
- Stop-Transcript
- New-BurntToastNotification @PrioritySplat -Text "Entering Hibernation in 60 seconds - close window to avoid"
- Start-Sleep -Seconds 60
- shutdown /h
- }
- else {
- Do
- {
- Write-Output "Waiting for Other PS Instance to close..."
- start-sleep -Second 15
- }
- Until ((get-process -name PowerShell -erroraction ignore) -eq $null -ne $PID)
- Start-UnattendedPowerPlanDisable
- write-output "`nEntering Hibernation in 60 seconds - close window to avoid"
- Stop-Transcript
- New-BurntToastNotification @PrioritySplat -Text "Entering Hibernation in 60 seconds - close window to avoid"
- Start-Sleep -Seconds 60
- shutdown /h
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment