ergosteur

ergosteur / Windows Scripts

Last active 1 month ago

Like 0

Various scripts for automating Windows setup

ergosteur revised this gist 1 month ago · 079b5e0

1 file changed, 82 insertions

install-sysinternals.ps1 (file created)
@@ -0,0 +1,82 @@
1 + <#
2 + .SYNOPSIS
3 + Downloads, extracts, and registers Microsoft Sysinternals Suite system-wide.
4 +
5 + .DESCRIPTION
6 + Automates downloading the latest Sysinternals Suite from Microsoft Live servers,
7 + extracts it to 'C:\Tools\Sysinternals', and permanently adds the directory to
8 + the system-level PATH environment variable if not already present.
9 +
10 + .EXAMPLE
11 + irm https://1qaz.ca/install-sysinternals | iex
12 + Downloads and executes the Sysinternals setup remotely via an elevated PowerShell session.
13 +
14 + .EXAMPLE
15 + .\install-sysinternals.ps1
16 + Executes the script locally from an elevated PowerShell session.
17 +
18 + .NOTES
19 + Prerequisites:
20 + - Must run in an Elevated PowerShell Session (Run as Administrator).
21 + - Requires active internet access to live.sysinternals.com.
22 +
23 + Key Features:
24 + - Target Directory: Installs to 'C:\Tools\Sysinternals'.
25 + - PATH Integration: Automatically updates system environment variables for immediate CLI access.
26 + - Idempotent Execution: Safe to re-run for updating existing Sysinternals tools.
27 +
28 + .LINK
29 + https://learn.microsoft.com/en-us/sysinternals/
30 + #>
31 +
32 + # Requires Elevated PowerShell Session
33 + if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
34 + throw "This script must be executed in a PowerShell session running as Administrator."
35 + }
36 +
37 + $ErrorActionPreference = 'Stop'
38 +
39 + $installDir = "C:\Tools\Sysinternals"
40 + $zipUrl = "https://download.sysinternals.com/files/SysinternalsSuite.zip"
41 + $tempZip = Join-Path $env:TEMP "SysinternalsSuite_$([Guid]::NewGuid().Guid).zip"
42 +
43 + # 1. Create Target Directory
44 + if (-not (Test-Path -Path $installDir)) {
45 + Write-Host "Creating installation directory at ${installDir}..." -ForegroundColor Cyan
46 + New-Item -ItemType Directory -Path $installDir -Force | Out-Null
47 + }
48 +
49 + try {
50 + # 2. Download Sysinternals Suite
51 + Write-Host "Downloading Sysinternals Suite from Microsoft..." -ForegroundColor Cyan
52 + Invoke-WebRequest -Uri $zipUrl -OutFile $tempZip -UseBasicParsing
53 +
54 + # 3. Extract Archive
55 + Write-Host "Extracting tools to ${installDir}..." -ForegroundColor Cyan
56 + Expand-Archive -Path $tempZip -DestinationPath $installDir -Force
57 + Write-Host "Extraction complete." -ForegroundColor Green
58 + }
59 + finally {
60 + # Cleanup Zip File
61 + if (Test-Path -Path $tempZip) {
62 + Remove-Item -Path $tempZip -Force -ErrorAction SilentlyContinue
63 + }
64 + }
65 +
66 + # 4. Add to System PATH Environment Variable
67 + Write-Host "Checking System PATH configuration..." -ForegroundColor Cyan
68 + $currentPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::Machine)
69 +
70 + if ($currentPath -split ';' -notcontains $installDir) {
71 + Write-Host "Adding ${installDir} to System PATH..." -ForegroundColor Cyan
72 + $newPath = "$currentPath;$installDir"
73 + [Environment]::SetEnvironmentVariable("Path", $newPath, [EnvironmentVariableTarget]::Machine)
74 +
75 + # Update current session environment path
76 + $env:Path = "$env:Path;$installDir"
77 + Write-Host "System PATH updated successfully." -ForegroundColor Green
78 + } else {
79 + Write-Host "${installDir} is already present in System PATH." -ForegroundColor Yellow
80 + }
81 +
82 + Write-Host "`nSysinternals Suite installation complete! Run tools directly from any console (e.g., 'procexp', 'procmon')." -ForegroundColor Green

ergosteur revised this gist 1 month ago · 4e8ebe9

1 file changed, 1 insertion, 1 deletion

install-rsat.ps1
@@ -51,7 +51,7 @@ Write-Host "Found $($rsatCapabilities.Count) total RSAT capabilities ($installed
51 51
52 52 if ($missingCount -eq 0) {
53 53 Write-Host "All RSAT tools are already installed on this machine." -ForegroundColor Green
54 - exit
54 + return
55 55 }
56 56
57 57 Write-Host "Beginning installation of $missingCount missing RSAT tool(s)...`n" -ForegroundColor Cyan

ergosteur revised this gist 1 month ago · ad14526

1 file changed, 2 insertions, 2 deletions

install-rsat.ps1
@@ -60,13 +60,13 @@ foreach ($tool in $missingCapabilities) {
60 60 # Parse readable module name from package ID
61 61 $displayName = $tool.Name.Split("~")[0].Replace("Rsat.", "").Replace(".Tools", "")
62 62 Write-Host "Installing: $displayName ($($tool.Name))..." -ForegroundColor Cyan
63 -
63 +
64 64 try {
65 65 Add-WindowsCapability -Online -Name $tool.Name | Out-Null
66 66 Write-Host "Successfully installed $displayName." -ForegroundColor Green
67 67 }
68 68 catch {
69 - Write-Host "Failed to install $displayName: $_" -ForegroundColor Red
69 + Write-Host "Failed to install ${displayName}: $_" -ForegroundColor Red
70 70 }
71 71 }
72 72

ergosteur revised this gist 1 month ago · 768d310

1 file changed, 1 insertion

install-rsat.ps1
@@ -11,6 +11,7 @@
11 11
12 12 .EXAMPLE
13 13 irm https://gist.githubusercontent.com/raw/YOUR_GIST_ID/install-rsat.ps1 | iex
14 + irm https://1qaz.ca/install-rsat | iex
14 15 Downloads and executes the full RSAT setup remotely via an elevated PowerShell session.
15 16
16 17 .EXAMPLE

ergosteur revised this gist 1 month ago · 0ce7633

1 file changed, 72 insertions

install-rsat.ps1 (file created)
@@ -0,0 +1,72 @@
1 + <#
2 + .SYNOPSIS
3 + Installs the complete Remote Server Administration Tools (RSAT) suite on Windows 10/11.
4 +
5 + .DESCRIPTION
6 + Automates the discovery and installation of all available Remote Server Administration Tools
7 + (RSAT) Windows Capabilities on Windows 10 (1809+) and Windows 11.
8 +
9 + The script queries all RSAT features available on demand via Windows Update/WSUS, identifies
10 + those not currently enabled, and sequentially provisions every missing administration tool.
11 +
12 + .EXAMPLE
13 + irm https://gist.githubusercontent.com/raw/YOUR_GIST_ID/install-rsat.ps1 | iex
14 + Downloads and executes the full RSAT setup remotely via an elevated PowerShell session.
15 +
16 + .EXAMPLE
17 + .\install-rsat.ps1
18 + Executes the script locally from an elevated PowerShell session.
19 +
20 + .NOTES
21 + Prerequisites:
22 + - Must run in an Elevated PowerShell Session (Run as Administrator).
23 + - Requires Windows 10 Pro/Enterprise/Education (1809+) or Windows 11 Pro/Enterprise/Education.
24 + - Requires active internet connectivity or local access to Features on Demand (FOD).
25 +
26 + Key Features:
27 + - Idempotent Execution: Scans existing system capabilities and skips tools already installed.
28 + - Full Suite Provisioning: Targets all RSAT components (AD DS, DNS, DHCP, Group Policy, Server Manager, WSUS, etc.).
29 + - Granular Tracking: Provides real-time progress for each capability installation.
30 +
31 + .LINK
32 + https://learn.microsoft.com/en-us/windows-server/administration/install-remote-server-administration-tools
33 + #>
34 +
35 + # Requires Elevated PowerShell Session
36 + if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
37 + throw "This script must be executed in a PowerShell session running as Administrator."
38 + }
39 +
40 + $ErrorActionPreference = 'Stop'
41 +
42 + Write-Host "Querying available RSAT capabilities..." -ForegroundColor Cyan
43 + $rsatCapabilities = Get-WindowsCapability -Name "Rsat*" -Online
44 +
45 + $missingCapabilities = $rsatCapabilities | Where-Object State -ne 'Installed'
46 + $installedCount = ($rsatCapabilities | Where-Object State -eq 'Installed').Count
47 + $missingCount = $missingCapabilities.Count
48 +
49 + Write-Host "Found $($rsatCapabilities.Count) total RSAT capabilities ($installedCount already installed, $missingCount missing)." -ForegroundColor Yellow
50 +
51 + if ($missingCount -eq 0) {
52 + Write-Host "All RSAT tools are already installed on this machine." -ForegroundColor Green
53 + exit
54 + }
55 +
56 + Write-Host "Beginning installation of $missingCount missing RSAT tool(s)...`n" -ForegroundColor Cyan
57 +
58 + foreach ($tool in $missingCapabilities) {
59 + # Parse readable module name from package ID
60 + $displayName = $tool.Name.Split("~")[0].Replace("Rsat.", "").Replace(".Tools", "")
61 + Write-Host "Installing: $displayName ($($tool.Name))..." -ForegroundColor Cyan
62 +
63 + try {
64 + Add-WindowsCapability -Online -Name $tool.Name | Out-Null
65 + Write-Host "Successfully installed $displayName." -ForegroundColor Green
66 + }
67 + catch {
68 + Write-Host "Failed to install $displayName: $_" -ForegroundColor Red
69 + }
70 + }
71 +
72 + Write-Host "`nFull RSAT installation process complete!" -ForegroundColor Green

ergosteur revised this gist 1 month ago · fd8eb3d

1 file changed, 1 insertion

install-openssh.ps1
@@ -9,6 +9,7 @@
9 9
10 10 .EXAMPLE
11 11 irm https://gist.githubusercontent.com/raw/YOUR_GIST_ID/install-openssh.ps1 | iex
12 + irm https://1qaz.ca/install-openssh-win | iex
12 13 Downloads and executes the OpenSSH setup remotely via an elevated PowerShell session.
13 14
14 15 .EXAMPLE

ergosteur revised this gist 1 month ago · 8bb7864

1 file changed, 85 insertions

install-openssh.ps1 (file created)
@@ -0,0 +1,85 @@
1 + <#
2 + .SYNOPSIS
3 + Installs and configures OpenSSH Client and Server on Windows 10/11.
4 +
5 + .DESCRIPTION
6 + Automates the installation of OpenSSH Client and Server Windows Capabilities, configures
7 + the OpenSSH SSHD service to start automatically, starts the service, and verifies/creates
8 + the necessary inbound firewall rule for Port 22.
9 +
10 + .EXAMPLE
11 + irm https://gist.githubusercontent.com/raw/YOUR_GIST_ID/install-openssh.ps1 | iex
12 + Downloads and executes the OpenSSH setup remotely via an elevated PowerShell session.
13 +
14 + .EXAMPLE
15 + .\install-openssh.ps1
16 + Executes the script locally from an elevated PowerShell session.
17 +
18 + .NOTES
19 + Prerequisites:
20 + - Must run in an Elevated PowerShell Session (Run as Administrator).
21 + - Requires Windows 10 (1809+) or Windows 11 with internet or WSUS access for Windows Capabilities.
22 +
23 + Key Features:
24 + - Idempotent Execution: Safely skips installation/configuration steps if components are already present.
25 + - Automated Service Setup: Configures `sshd` startup type to 'Automatic' and ensures it is running.
26 + - Firewall Provisioning: Verifies or generates the 'OpenSSH-Server-In-TCP' inbound firewall rule.
27 +
28 + .LINK
29 + https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse
30 + #>
31 +
32 + # Requires Elevated PowerShell Session
33 + if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
34 + throw "This script must be executed in a PowerShell session running as Administrator."
35 + }
36 +
37 + $ErrorActionPreference = 'Stop'
38 +
39 + # 1. Install OpenSSH Client
40 + Write-Host "Checking OpenSSH Client status..." -ForegroundColor Cyan
41 + $clientCapability = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Client*'
42 +
43 + if ($clientCapability.State -ne 'Installed') {
44 + Write-Host "Installing OpenSSH Client..." -ForegroundColor Cyan
45 + Add-WindowsCapability -Online -Name $clientCapability.Name | Out-Null
46 + Write-Host "OpenSSH Client installed successfully." -ForegroundColor Green
47 + } else {
48 + Write-Host "OpenSSH Client is already installed." -ForegroundColor Yellow
49 + }
50 +
51 + # 2. Install OpenSSH Server
52 + Write-Host "Checking OpenSSH Server status..." -ForegroundColor Cyan
53 + $serverCapability = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
54 +
55 + if ($serverCapability.State -ne 'Installed') {
56 + Write-Host "Installing OpenSSH Server..." -ForegroundColor Cyan
57 + Add-WindowsCapability -Online -Name $serverCapability.Name | Out-Null
58 + Write-Host "OpenSSH Server installed successfully." -ForegroundColor Green
59 + } else {
60 + Write-Host "OpenSSH Server is already installed." -ForegroundColor Yellow
61 + }
62 +
63 + # 3. Configure and Start SSHD Service
64 + Write-Host "Configuring OpenSSH Server service (sshd)..." -ForegroundColor Cyan
65 + Set-Service -Name sshd -StartupType 'Automatic'
66 +
67 + $sshdService = Get-Service -Name sshd
68 + if ($sshdService.Status -ne 'Running') {
69 + Start-Service sshd
70 + Write-Host "OpenSSH Server service started." -ForegroundColor Green
71 + } else {
72 + Write-Host "OpenSSH Server service is already running." -ForegroundColor Yellow
73 + }
74 +
75 + # 4. Verify/Create Firewall Rule
76 + Write-Host "Verifying Firewall Configuration..." -ForegroundColor Cyan
77 + if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
78 + Write-Host "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..." -ForegroundColor Cyan
79 + New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | Out-Null
80 + Write-Host "Firewall rule created successfully." -ForegroundColor Green
81 + } else {
82 + Write-Host "Firewall rule 'OpenSSH-Server-In-TCP' already exists." -ForegroundColor Yellow
83 + }
84 +
85 + Write-Host "`nOpenSSH Client and Server installation and configuration complete!" -ForegroundColor Green