Cogger

I0-ScheduledTasks-Modifications.ps1

Jun 13th, 2022
442
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ########################################################################################################################
  2. #=====[ Scheduled Tasks ]=====#
  3. ########################################################################################################################
  4.  
  5. #=====[ Creating Scheduled Task ]=====#
  6. # Create script for Active Setup
  7. Write-Host('Creating script for active setup...') -Fore White
  8. Set-Content -Path 'C:\Automation\atom.ps1' -Value {
  9.  
  10. Invoke-Expression 'cmd /c start powershell -Command { powershell.exe "C:\Automation\Win-Update.ps1" }'
  11. Invoke-Expression 'cmd /c start powershell -Command { powershell.exe "C:\Automation\RipMe.ps1" }'
  12. Invoke-Expression 'cmd /c start powershell -Command { powershell.exe "C:\Automation\Choco.ps1" }'
  13. Invoke-Expression 'cmd /c start powershell -Command { powershell.exe "C:\Automation\WSL_Ubunutu_01.ps1"}'
  14. }
  15.  
  16. # Set the registry key for Active-Setup
  17. Write-Host('Settings registry key for active setup...') -Fore White
  18. reg add "HKLM\Software\Microsoft\Active Setup\Installed Components\ATOM" /v "StubPath" /d "Powershell.exe C:\Automation\atom.ps1" /t REG_SZ /f
  19.  
  20.  
  21. ### Create task to reboot after updates have been installed.
  22. Write-Host('Creating Scheduled Task to reboot after applying updates...') -Fore White
  23. $ScriptLocation = 'C:\Automation\Reboot.ps1'
  24. $day = 'Monday'
  25. $time = '1am'
  26. $Task = 'Reboot to apply Windows Updates'
  27. $TaskAction = New-ScheduledTaskAction -Execute $ScriptLocation
  28. $TaskTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek $day -At $time
  29. Register-ScheduledTask -Action $TaskAction -Trigger $Tasktrigger -TaskName $Task -User "System" -RunLevel Highest
  30.  
  31. ### Create task to Set a Restore point, clean the disk, and download and apply updates.
  32. Write-Host('Creating Scheduled Task to Apply updates...') -Fore White
  33. $ScriptLocation = 'C:\Automation\AutomaticAdministration.ps1'
  34. $day = 'Sunday'
  35. $time = '9pm'
  36. $Task = 'Apply Windows Updates'
  37. $TaskAction = New-ScheduledTaskAction -Execute $ScriptLocation
  38. $TaskTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek $day -At $time
  39. Register-ScheduledTask -Action $TaskAction -Trigger $Tasktrigger -TaskName $Task -User "System" -RunLevel Highest
  40.  
  41. Set-Content -Path 'C:\Automation\WSL_Ubunutu_00.ps1' -Value {
  42.     Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
  43.     Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
  44.     Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart
  45.    
  46.     Set-Content -Path 'C:\Automation\WSL_Ubunutu_01.ps1' -Value {
  47.     # Download and install the framework needed for windows Subsystem
  48.     Start-BitsTransfer -Source "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -Destination "C:\Automation\wsl_update_x64.msi"
  49.     Start-Process msiexec.exe -Wait -ArgumentList '/I C:\Automation\wsl_update_x64.msi /quiet'
  50.  
  51.     # Wait until the application is installed before proceeding
  52.     do {
  53.         Start-Sleep -Seconds 1
  54.         $LNXCHeck = (get-wmiobject Win32_Product | Sort-Object -Property Name |  Where-Object Name -match "Windows SubSystem for Linux Update").Name
  55.         $LNXName  = "Windows SubSystem for Linux Update"
  56.         $TestLNX = $LNXName -eq $LNXCHeck
  57.     } until ($TestLNX -eq $true)
  58.  
  59.     # Set the subsystem preference to version 2
  60.     invoke-expression 'cmd /c start powershell -Command { wsl --set-default-version 2 }' ; Start-Sleep -s 7
  61.  
  62.     # Download Ubuntu
  63.     $ProgressPreference = 'SilentlyContinue'
  64.     Invoke-WebRequest -Uri https://aka.ms/wslubuntu -OutFile C:\Automation\Ubuntu.appx -UseBasicParsing
  65.  
  66.     # If Ubuntu did not download; then attempt to another method
  67.     $UbuApx = "C:\Automation\Ubuntu.appx"
  68.     if (Test-Path -Path $UbuApx) {
  69.     # IF File exists continue
  70.    
  71.         } else {
  72.     # IF File does not exist download and then continue
  73.     Start-BitsTransfer -Source "https://wslstorestorage.blob.core.windows.net/wslblob/CanonicalGroupLimited.UbuntuonWindows_2004.2021.825.0.AppxBundle" -Destination "C:\Automation\Ubuntu.appx"
  74.     }
  75.  
  76.     # Install this the Ubuntu Package
  77.     Add-AppxPackage C:\Automation\Ubuntu.appx ; Start-Sleep -s 7
  78.    
  79.     # Launch bash first time to install updates
  80.     invoke-expression 'cmd /c start powershell -Command { Start bash }'
  81.  
  82.     }
  83.  
  84. }
  85.  
  86.  
  87. #=====[ Disabling Scheduled Tasks ]=====#
  88.  
  89. $DisableTasks = @(
  90.  
  91.     #Disable Tasks
  92.     "Windows Defender Cache Maintenance"
  93.     "Windows Defender Cleanup"
  94.     "Windows Defender Scheduled Scan"
  95.     "Windows Defender Verification"
  96.     "QueueReporting"
  97.     "Microsoft Compatibility Appraiser"
  98.     "ProgramDataUpdater"
  99.     "StartupAppTask"
  100.     "Proxy"
  101.     "CreateObjectTask"
  102.     "Consolidator"
  103.     "UsbCeip"
  104.     "Microsoft-Windows-DiskDiagnosticDataCollector"
  105.     "DmClient"
  106.     "DmClientOnScenarioDownload"
  107.     "FamilySafetyMonitor"
  108.     "FamilySafetyRefreshTask"
  109.     "ScheduledDefrag"
  110.     "SaveTask"
  111.     "SaveTaskLogon"
  112.     "DmClientOnScenarioDownload "
  113.     "OfficeTelemetryAgentFallBack2016 "
  114.     "OfficeTelemetryAgentLogOn2016"
  115.     "XblGameSaveTask"
  116.     "XblGameSaveTaskLogon"
  117.  
  118.     )
  119.     foreach ($disTask in $DisableTasks) {
  120.         Get-ScheduledTask -TaskName $disTask | Disable-ScheduledTask -ErrorAction SilentlyContinue | Out-Null
  121.         }
  122.  
Advertisement
Add Comment
Please, Sign In to add comment