Laptop terminal pushing scheduled updates to a row of servers that all report success

Automating Windows Updates Across Multiple Servers with PowerShell

Managing Windows updates across multiple servers doesn’t have to be a manual, time-consuming process. With PowerShell and the PSWindowsUpdate module, you can automate the entire update process from a single session. This script creates scheduled tasks across multiple servers that will automatically install Windows updates and reboot when necessary: # Create scheduled task on all servers that runs in 2 minutes Invoke-Command -ComputerName $servers -ScriptBlock { $action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument @" -ExecutionPolicy Bypass -Command " if (!(Get-Module -List PSWindowsUpdate)) { Install-PackageProvider -Name NuGet -Force Install-Module PSWindowsUpdate -Force } Import-Module PSWindowsUpdate Install-WindowsUpdate -AcceptAll -AutoReboot | Out-File C:\PSWindowsUpdate.log " "@ $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddSeconds(30) $principal = New-ScheduledTaskPrincipal -UserId "SYSTEM" -LogonType ServiceAccount -RunLevel Highest Register-ScheduledTask -TaskName "WindowsUpdateInstall" -Action $action -Trigger $trigger -Principal $principal -Force Write-Host "$env:COMPUTERNAME : Task created, updates starting in 2 minutes" } -ThrottleLimit 50 Scheduled Task Approach: Instead of running updates immediately, the script creates a scheduled task on each server. This allows your PowerShell session to complete quickly while updates run independently with proper system privileges. ...

June 19, 2025 · 2 min · thomasf
settings

Monitoring Event Logs in Windows with PowerShell: A Script for Recent Events

When managing a Windows environment, analyzing event logs is an essential part of troubleshooting. Windows logs a wide range of system, security, and application events, but sometimes specific problems can arise without easily accessible evidence. For example, when tracking down recent events, it can be cumbersome to manually check each log for relevant entries. In this post, I’ll share a simple PowerShell script that extracts recent log entries across all event logs—not just the default System, Application, and Security logs. This script is particularly useful when you need to quickly review what’s been happening on your machine over the last 5 minutes. ...

September 10, 2024 · 4 min · thomasf

Use PowerShell Invoke-WebRequest to login on a website

To automate some tasks with PowerShell on a website you sometimes need to log in. Today I tried some curl and postman tricks but it isn’t hard if you know what to script with PowerShell and bypass all other tools. First, find a website to log in to, then check the page source and what the submit button does. In this example, it is “Inloggen” (dutch for login). Then start the developer tools (F12), select the network tab, enter the credentials and login. ...

October 4, 2022 · 3 min · thomasf
windows-powershell-ise-icon

Update Windows Server with powershell

This is for 2016 server. But it will work for other versions of Windows [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted Install-Module PSWindowsUpdate -Confirm:$false Set-PSRepository -Name "PSGallery" -InstallationPolicy Untrusted Get-WindowsUpdate -AcceptAll -Install -AutoReboot Happy Patching :)

September 20, 2022 · 1 min · thomasf

Configure WSUS client with Powershell and Regedit

My use case for a customer was to configure WSUS for a couple of DMZ servers. The DMZ servers are not domain-joined. So I create a PowerShell script to configure the registry so I can easily deploy the settings to the servers. You can use this script also for non domain-joined servers # Script for WSUS configuration on non-domain joined servers # First stop the Windows service Get-Service -name wuauserv | stop-service # Variables $registryPath = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" $name1 = "TargetGroup" $value1 = "Production" $name2 = "WUServer" $value2 = "http://wsus.domain.local:8530" $name3 = "WUStatusServer" $value3 = "http://wsus.domain.local:8530" $name4 = "DoNotConnectToWindowsUpdateInternetLocations" $value4 = "1" $name5 = "TargetGroupEnabled" $value5 = "1" $registryPathAU = "HKLM:\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU" $nameAU1 = "AUOptions" $valueAU1 = "3" $nameAU2 = "UseWUServer" $valueAU2 = "1" # Inject registry IF(!(Test-Path $registryPath)) { New-Item -Path $registryPath -Force | Out-Null New-ItemProperty -Path $registryPath -Name $name1 -Value $value1 -Force | Out-Null New-ItemProperty -Path $registryPath -Name $name2 -Value $value2 -Force | Out-Null New-ItemProperty -Path $registryPath -Name $name3 -Value $value3 -Force | Out-Null New-ItemProperty -Path $registryPath -Name $name4 -Value $value4 -PropertyType DWORD -Force | Out-Null New-ItemProperty -Path $registryPath -Name $name5 -Value $value5 -PropertyType DWORD -Force | Out-Null } ELSE { New-ItemProperty -Path $registryPath -Name $name1 -Value $value1 -Force | Out-Null New-ItemProperty -Path $registryPath -Name $name2 -Value $value2 -Force | Out-Null New-ItemProperty -Path $registryPath -Name $name3 -Value $value3 -Force | Out-Null New-ItemProperty -Path $registryPath -Name $name4 -Value $value4 -PropertyType DWORD -Force | Out-Null New-ItemProperty -Path $registryPath -Name $name5 -Value $value5 -PropertyType DWORD -Force | Out-Null } IF(!(Test-Path $registryPathAU)) { New-Item -Path $registryPathAU -Force | Out-Null New-ItemProperty -Path $registryPathAU -Name $nameAU1 -Value $valueAU1 -PropertyType DWORD -Force | Out-Null New-ItemProperty -Path $registryPathAU -Name $nameAU2 -Value $valueAU2 -PropertyType DWORD -Force | Out-Null } ELSE { New-ItemProperty -Path $registryPathAU -Name $nameAU1 -Value $valueAU1 -PropertyType DWORD -Force | Out-Null New-ItemProperty -Path $registryPathAU -Name $nameAU2 -Value $valueAU2 -PropertyType DWORD -Force | Out-Null } # Start the Windows service Get-Service -name wuauserv | start-service # Find updates and report to the WSUS server $updateSession = new-object -com "Microsoft.Update.Session"; $updates=$updateSession.CreateupdateSearcher().Search($criteria).Updates Start-sleep -seconds 10 wuauclt /detectnow wuauclt /reportnow c:\windows\system32\UsoClient.exe startscan I save this file on the WSUS server itself at http://wsus.domain.local:8530/script.txt so I can download and run it from the DMZ environment. ...

May 10, 2022 · 2 min · thomasf

Powershell better tab autocomplete

With Powershell ISE you can use CTRL + SPACE for auto completion. But when you work in a native Powershell window you don’t have this option. And many often you cycle with tab completion trough the powershell and because you press the TAB button too soon you have to remove characters and cycle again trough all the commands. Unit now ;-) There is an easy fix you can implement so the Powershell have the same auto completion like bash. ...

April 5, 2022 · 1 min · thomasf
windows-powershell-ise-icon

Add Powershell 7 to your Powershell ISE

I find this code snippet somewhere on the internet and I like it :) Just open ISE and paste these code and you are ready to rock! $ErrorActionPreference= 'silentlycontinue' $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Clear() $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to PowerShell 7", { function New-OutOfProcRunspace { param($ProcessId) $ConnInfo = New-Object -TypeName System.Management.Automation.Runspaces.NamedPipeConnectionInfo -ArgumentList @($ProcessId) $DefaultType = [System.Management.Automation.Runspaces.TypeTable]::LoadDefaultTypeFiles() $Runspace = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace($ConnInfo, $Host, $Default) $Runspace.Open() $Runspace } $PowerShell = Start-Process PWSH -ArgumentList @("-NoExit") -PassThru -WindowStyle Hidden $Runspace = New-OutOfProcRunspace -ProcessId $PowerShell.Id $Host.PushRunspace($Runspace) }, "ALT+F5") | Out-Null $psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Switch to PowerShell 5", { $Host.PopRunspace() $ChildProc = Get-CimInstance -ClassName win32_process | where {$_.ParentProcessId -eq $Pid} $ChildProc | ForEach-Object { Stop-Process -Id $_.ProcessId } }, "ALT+F6") | Out-Null Happy coding!

April 2, 2022 · 1 min · thomasf

Powershell run *.exe files

There are 2 ways to run an executable within powershell without any errors $exe = 'C:\scripts\Everything.exe' $param1 = '-reindex' & $exe $param1 Or with a –% attribute C:\windows\system32\sc.exe --% qc bits

January 1, 2022 · 1 min · thomasf
Shell

Create Azure Linux VM with worpress pre-installed

This is my first completed automated Linux Azure VM deployment. I like to share it with you. There are 3 parts Create a keygen for ssh Powershell script Bash script First start powershell and create a keypair with passphase ssh-keygen -m PEM -t rsa -b 4096 Then place the bash script somewhere on your local computer #! /bin/bash apt-get update apt-get install -y wordpress php libapache2-mod-php mysql-server php-mysql echo "Alias /blog /usr/share/wordpress" >>/etc/apache2/sites-available/wordpress.conf echo "" >>/etc/apache2/sites-available/wordpress.conf echo " Options FollowSymLinks" >>/etc/apache2/sites-available/wordpress.conf echo " AllowOverride Limit Options FileInfo" >>/etc/apache2/sites-available/wordpress.conf echo " DirectoryIndex index.php" >>/etc/apache2/sites-available/wordpress.conf echo " Order allow,deny" >>/etc/apache2/sites-available/wordpress.conf echo " Allow from all" >>/etc/apache2/sites-available/wordpress.conf echo "" >>/etc/apache2/sites-available/wordpress.conf echo "" >>/etc/apache2/sites-available/wordpress.conf echo " Options FollowSymLinks" >>/etc/apache2/sites-available/wordpress.conf echo " Order allow,deny" >>/etc/apache2/sites-available/wordpress.conf echo " Allow from all" >>/etc/apache2/sites-available/wordpress.conf echo "" >>/etc/apache2/sites-available/wordpress.conf a2ensite wordpress a2enmod rewrite reload apache2 service apache2 reload systemctl restart apache2 mysql -e "CREATE DATABASE wordpress;" mysql -e "CREATE USER wordpress@localhost IDENTIFIED BY 'Secret@Pass1';" mysql -e "GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER ON wordpress.* TO wordpress@localhost;" mysql -e "FLUSH PRIVILEGES;" echo ">/etc/wordpress/config-localhost.php echo "define('DB_NAME', 'wordpress');">>/etc/wordpress/config-localhost.php echo "define('DB_USER', 'wordpress');">>/etc/wordpress/config-localhost.php echo "define('DB_PASSWORD', 'Secret@Pass1');">>/etc/wordpress/config-localhost.php echo "define('DB_HOST', 'localhost');">>/etc/wordpress/config-localhost.php echo "define('DB_COLLATE', 'utf8_general_ci');">>/etc/wordpress/config-localhost.php echo "define('WP_CONTENT_DIR', '/usr/share/wordpress/wp-content');">>/etc/wordpress/config-localhost.php echo "?>">>/etc/wordpress/config-localhost.php service mysql start publicip=$(dig +short myip.opendns.com @resolver1.opendns.com) && mv /etc/wordpress/config-localhost.php /etc/wordpress/config-$publicip.php Then put the code in the Powershell ISE, change some variables and kickoff the script. ...

February 6, 2021 · 3 min · thomasf