Skip to content

Scripts Windows Utilities

Quadstronaut edited this page Jun 7, 2026 · 1 revision

Scripts: Windows Utilities

Scripts in Scripts/Windows/Utilities/.


Get-OpenWindows.ps1

What it does: Lists all running processes that have a visible main window, showing their process name and window title.

Parameters: None. No admin rights required.

Usage:

.\Scripts\Windows\Utilities\Get-OpenWindows.ps1

Example output:

--- Active Window Titles ---
ProcessName             MainWindowTitle
--------------------------------------------------------
Code                    Sync-Directories.ps1 - PotentPowershell - Visual Studio Code
WindowsTerminal         PowerShell
msedge                  GitHub - Microsoft Edge

Use case: When writing automation scripts that target windows by title (e.g., Set-WindowPosition, SendKeys, AutoHotkey integration), use this script to find the exact MainWindowTitle string for the window you want to target.


Set-AdminAutoElevate.ps1

What it does: Configures PowerShell to auto-elevate every new window to admin.

Steps performed:

  1. Auto-elevates if not already admin.
  2. Sets execution policy to Unrestricted for the current user.
  3. Creates the PowerShell profile file (Microsoft.PowerShell_profile.ps1) if it does not exist.
  4. Appends an auto-elevation snippet to the profile that re-launches any non-admin PowerShell window as admin.
  5. Dot-sources the profile to apply changes immediately.

Parameters: None.

Requirements: Auto-elevates if not admin.

Usage:

.\Scripts\Windows\Utilities\Set-AdminAutoElevate.ps1

Security note: This script sets the execution policy to Unrestricted for the current user, which allows any local or remote script to run without a prompt. RemoteSigned is a safer alternative — it still requires local scripts to be unblocked but blocks remote scripts without a trusted signature. If you want RemoteSigned behavior, edit the script before running:

# Change this line in the script:
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force
# To:
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

Profile location: $env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

This is the Windows PowerShell 5.1 profile path. PowerShell 7 uses a different profile path ($env:USERPROFILE\Documents\PowerShell\Microsoft.PowerShell_profile.ps1). If you use both, run the snippet appended to each profile separately.


Remove-Silverlight.ps1

What it does: Completely removes Microsoft Silverlight from the system.

Microsoft Silverlight reached end-of-life in October 2021. No modern browser supports it. Removing it reduces attack surface.

Steps performed:

  1. Locates Silverlight.Configuration.exe in C:\Program Files (x86)\Microsoft Silverlight\.
  2. Runs the silent uninstaller (/uninstall /force /silent).
  3. Removes registry entries under HKLM:\Software\Microsoft\Silverlight and the Silverlight uninstall key.
  4. Deletes C:\Program Files (x86)\Microsoft Silverlight directory.
  5. Deletes the Silverlight browser plugin from %AppData%\Microsoft\Plugins.

Parameters: None.

Requirements: Administrator access recommended (registry and Program Files). Safe no-op if Silverlight is not installed.

Usage:

.\Scripts\Windows\Utilities\Remove-Silverlight.ps1

Get-ScreenGeometry.ps1

What it does: Reports the full Bounds and WorkingArea for each connected monitor, using System.Windows.Forms.Screen.

Parameters: None. No admin rights required.

Usage:

.\Scripts\Windows\Utilities\Get-ScreenGeometry.ps1

Example output:

--- Your Screen Geometry ---

Screen #1
  Primary      : True
  Bounds       : X=0, Y=0, W=2560, H=1440
  Working Area : X=0, Y=0, W=2560, H=1400
  Device Name  : \\.\DISPLAY1

Screen #2
  Primary      : False
  Bounds       : X=2560, Y=0, W=1920, H=1080
  Working Area : X=2560, Y=0, W=1920, H=1080
  Device Name  : \\.\DISPLAY2

Bounds vs WorkingArea:

  • Bounds — the full physical screen rectangle, including any space the taskbar occupies.
  • WorkingArea — the usable area excluding the taskbar. Use this for window placement so windows don't appear behind the taskbar.

Use case: Window management scripts that need to position windows relative to monitor boundaries. The Bounds.X of a secondary monitor is its offset from the primary (usually primary.Width).


Sync-Directories.ps1

What it does: Copies all files from a source directory to a destination using Robocopy with 64 parallel threads.

Parameters:

Parameter Type Required Description
-Source string Yes The source directory to copy from
-Destination string Yes The destination directory to copy to

Robocopy flags used:

Flag Meaning
/E Copy subdirectories, including empty ones
/XC Exclude changed files (skip files that already exist with the same timestamp)
/NP No per-file progress percentage (reduces output noise)
/ETA Show estimated time of arrival for each file
/MT:64 Use 64 parallel threads

Usage:

# Sync a local directory to a backup location
.\Scripts\Windows\Utilities\Sync-Directories.ps1 -Source "D:\Data" -Destination "E:\Backup\Data"

# Sync from a network share to local
.\Scripts\Windows\Utilities\Sync-Directories.ps1 -Source "\\server\share" -Destination "C:\LocalCopy"

Exit codes: Robocopy uses a bitmap exit code. This script treats codes 0–3 as success and codes ≥ 4 as a warning:

Code Meaning
0 No files copied (destination already in sync)
1 Files copied successfully
2 Extra files detected in destination (not an error)
3 Some files copied + extra files in destination
4 Mismatched files
8 Some files could not be copied (check for permission errors)
16 Fatal error

Notes:

  • /MT:64 uses 64 I/O threads. On slow storage (especially HDDs or slow network shares), high thread counts can cause seek thrashing. Reduce to /MT:8 or /MT:16 if you experience this.
  • /XC skips files with matching timestamps — it does not compare file contents. If you need content-based deduplication, use /XCT or a different tool.
  • This script does not mirror (delete destination files not in source). Use /MIR in Robocopy if you need mirror behavior, but be careful — /MIR deletes.

Start-MSRewards.ps1

What it does: Opens Microsoft Edge to the MS Edge Search Clicker page, waits a configurable number of seconds, then closes Edge.

Intended for automated daily Microsoft Rewards search point accumulation.

Parameters:

Parameter Type Default Description
-WaitSeconds int 120 Seconds to keep Edge open before closing

Requirements: Microsoft Edge installed at C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe. If Edge is installed elsewhere, update the $edgePath variable in the script.

Usage:

# Default: 120 seconds
.\Scripts\Windows\Utilities\Start-MSRewards.ps1

# Custom wait time
.\Scripts\Windows\Utilities\Start-MSRewards.ps1 -WaitSeconds 180

Notes:

  • The script uses Stop-Process -Name 'msedge' to close Edge — this closes all Edge windows, not just the one it opened. Do not run other Edge sessions you need to keep when using this script.
  • The search clicker URL (https://greybax.github.io/MSEdgeSearchClicker) is a third-party tool. Verify it still functions and complies with Microsoft Rewards terms of service before use. Microsoft's ToS for Rewards programs can restrict automated point collection.
  • If Edge is not found at the hardcoded path, the script exits with a warning and does nothing.

Clone this wiki locally