Skip to content

PowerShell script

mhtvsSFrpHdE edited this page Oct 7, 2022 · 8 revisions

PowerShell script

Basic

All the script should run as admin.
You can open file explorer and navigate to script folder,
go File\Open Windows PowerShell\Open Windows PowerShell as administrator

To run a script, first do Set-ExecutionPolicy Unrestricted to allow ps1 to run.
The command should run twice, one for Admin and one for user.
See Microsoft about_Execution_Policies for more details.

Windows Update scripts depends on PSWindowsUpdate, so
Install-Module PSWindowsUpdate.

After allow, use .\<script name>.ps1 to actually run a script.
Use Tab key to autocomplete script name.

You can always use notepad to open .ps1 file to view what actually being modified.

All_Disable.ps1

The Editor's Choice one.
Execute the following script at once, be sure to read correspond document before run:

Wu_Disable.ps1

Disable Windows update service (wuauserv), request stop, then change to disabled.
However, the Windows update task scheduler may still run.

WuTask_Disable.ps1

Disable Windows update task scheduler, will first run Wu_Disable.ps1 once.
You need to run twice, the first execute will only dump exist task but not disable it.
For example, if you see Please run again on console output,
then run again, whatever you are doing. It may look like:

> .\All_Disable.ps1
Please run again
> .\All_Disable.ps1    // <- Run again

Wu_Enable.ps1

Enable and start Windows update service, change to manually, then request start.
However, the Windows update task will not get a restore,
you need to go Task Scheduler manually if necessary.

Wu_RunOnce.ps1

The one use rather complex control flow to update Windows once.

  • Enable Windows Update service temporarily
  • Hide Windows Malicious Software Removal Tool from update list
  • Open setting and navigate to Windows Update
  • Start update process

After install complete, basically the system will reboot so:

  • Schedule a "run once" task at next boot
  • After login, wait 5 minutes to complete update
  • In the run once task, disable Windows Update service

Notice: the disable Windows Update will not run if reboot finally not happen.
In case just reboot manually. The script has no track on update result.

Eu_Disable.ps1

There are Edge browser update task, disable them can reduce HDD usage during boot.
For an HDD, less total usage, less lag (ka le).

The script will also replace Edge update with a dummy EXE file,
because even the update task is disabled, Windows still run edge updater on boot.
This action has no backup, so you need to reinstall Edge to get the original updater back.
Or do backup manually before run.

Clone this wiki locally