Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ########################################################################################################################
- #=====[ Scheduled Tasks ]=====#
- ########################################################################################################################
- #=====[ Creating Scheduled Task ]=====#
- # Create script for Active Setup
- Write-Host('Creating script for active setup...') -Fore White
- Set-Content -Path 'C:\Automation\atom.ps1' -Value {
- Invoke-Expression 'cmd /c start powershell -Command { powershell.exe "C:\Automation\Win-Update.ps1" }'
- Invoke-Expression 'cmd /c start powershell -Command { powershell.exe "C:\Automation\RipMe.ps1" }'
- Invoke-Expression 'cmd /c start powershell -Command { powershell.exe "C:\Automation\Choco.ps1" }'
- Invoke-Expression 'cmd /c start powershell -Command { powershell.exe "C:\Automation\WSL_Ubunutu_01.ps1"}'
- }
- # Set the registry key for Active-Setup
- Write-Host('Settings registry key for active setup...') -Fore White
- reg add "HKLM\Software\Microsoft\Active Setup\Installed Components\ATOM" /v "StubPath" /d "Powershell.exe C:\Automation\atom.ps1" /t REG_SZ /f
- ### Create task to reboot after updates have been installed.
- Write-Host('Creating Scheduled Task to reboot after applying updates...') -Fore White
- $ScriptLocation = 'C:\Automation\Reboot.ps1'
- $day = 'Monday'
- $time = '1am'
- $Task = 'Reboot to apply Windows Updates'
- $TaskAction = New-ScheduledTaskAction -Execute $ScriptLocation
- $TaskTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek $day -At $time
- Register-ScheduledTask -Action $TaskAction -Trigger $Tasktrigger -TaskName $Task -User "System" -RunLevel Highest
- ### Create task to Set a Restore point, clean the disk, and download and apply updates.
- Write-Host('Creating Scheduled Task to Apply updates...') -Fore White
- $ScriptLocation = 'C:\Automation\AutomaticAdministration.ps1'
- $day = 'Sunday'
- $time = '9pm'
- $Task = 'Apply Windows Updates'
- $TaskAction = New-ScheduledTaskAction -Execute $ScriptLocation
- $TaskTrigger = New-ScheduledTaskTrigger -Weekly -DaysOfWeek $day -At $time
- Register-ScheduledTask -Action $TaskAction -Trigger $Tasktrigger -TaskName $Task -User "System" -RunLevel Highest
- Set-Content -Path 'C:\Automation\WSL_Ubunutu_00.ps1' -Value {
- Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatform -NoRestart
- Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart
- Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All -NoRestart
- Set-Content -Path 'C:\Automation\WSL_Ubunutu_01.ps1' -Value {
- # Download and install the framework needed for windows Subsystem
- Start-BitsTransfer -Source "https://wslstorestorage.blob.core.windows.net/wslblob/wsl_update_x64.msi" -Destination "C:\Automation\wsl_update_x64.msi"
- Start-Process msiexec.exe -Wait -ArgumentList '/I C:\Automation\wsl_update_x64.msi /quiet'
- # Wait until the application is installed before proceeding
- do {
- Start-Sleep -Seconds 1
- $LNXCHeck = (get-wmiobject Win32_Product | Sort-Object -Property Name | Where-Object Name -match "Windows SubSystem for Linux Update").Name
- $LNXName = "Windows SubSystem for Linux Update"
- $TestLNX = $LNXName -eq $LNXCHeck
- } until ($TestLNX -eq $true)
- # Set the subsystem preference to version 2
- invoke-expression 'cmd /c start powershell -Command { wsl --set-default-version 2 }' ; Start-Sleep -s 7
- # Download Ubuntu
- $ProgressPreference = 'SilentlyContinue'
- Invoke-WebRequest -Uri https://aka.ms/wslubuntu -OutFile C:\Automation\Ubuntu.appx -UseBasicParsing
- # If Ubuntu did not download; then attempt to another method
- $UbuApx = "C:\Automation\Ubuntu.appx"
- if (Test-Path -Path $UbuApx) {
- # IF File exists continue
- } else {
- # IF File does not exist download and then continue
- Start-BitsTransfer -Source "https://wslstorestorage.blob.core.windows.net/wslblob/CanonicalGroupLimited.UbuntuonWindows_2004.2021.825.0.AppxBundle" -Destination "C:\Automation\Ubuntu.appx"
- }
- # Install this the Ubuntu Package
- Add-AppxPackage C:\Automation\Ubuntu.appx ; Start-Sleep -s 7
- # Launch bash first time to install updates
- invoke-expression 'cmd /c start powershell -Command { Start bash }'
- }
- }
- #=====[ Disabling Scheduled Tasks ]=====#
- $DisableTasks = @(
- #Disable Tasks
- "Windows Defender Cache Maintenance"
- "Windows Defender Cleanup"
- "Windows Defender Scheduled Scan"
- "Windows Defender Verification"
- "QueueReporting"
- "Microsoft Compatibility Appraiser"
- "ProgramDataUpdater"
- "StartupAppTask"
- "Proxy"
- "CreateObjectTask"
- "Consolidator"
- "UsbCeip"
- "Microsoft-Windows-DiskDiagnosticDataCollector"
- "DmClient"
- "DmClientOnScenarioDownload"
- "FamilySafetyMonitor"
- "FamilySafetyRefreshTask"
- "ScheduledDefrag"
- "SaveTask"
- "SaveTaskLogon"
- "DmClientOnScenarioDownload "
- "OfficeTelemetryAgentFallBack2016 "
- "OfficeTelemetryAgentLogOn2016"
- "XblGameSaveTask"
- "XblGameSaveTaskLogon"
- )
- foreach ($disTask in $DisableTasks) {
- Get-ScheduledTask -TaskName $disTask | Disable-ScheduledTask -ErrorAction SilentlyContinue | Out-Null
- }
Advertisement
Add Comment
Please, Sign In to add comment