11 June 2026

How to fix PowerShell Graph module version mismatches

 Sometimes Graph module will get scrambled and some commands are working and some are thowing errors. I also needed to have Graph Beta module for one specific need and those commands run as administrator and running as the specific account (to remove currentuser scope versions too) fixed the headache (first line uninstalls all graph modules, second one installs normal Graph module and third line installs the Beta version of Graph module):

Get-InstalledModule Microsoft.Graph* | Uninstall-Module -AllVersions -Force

Install-Module Microsoft.Graph -Scope AllUsers -Force

Install-Module Microsoft.Graph.Beta -Scope AllUsers -Force

20 April 2026

Install PowerShell 7 with automatic update

 Paste this script into administrative PowerShell prompt (version 5 is ok) and it will install newest version of PowerShell with the option to update it using Microsoft Update.

$rel = Invoke-RestMethod 'https://api.github.com/repos/PowerShell/PowerShell/releases/latest'

$url = ($rel.assets | Where-Object name -like 'PowerShell-*-win-x64.msi').browser_download_url

$file = "$env:TEMP\pwsh-latest-x64.msi"

$ProgressPreference = 'SilentlyContinue'

Invoke-WebRequest -Uri $url -OutFile $file

Start-Process msiexec.exe -Wait -ArgumentList "/i `"$file`" /quiet /norestart ADD_PATH=1 USE_MU=1 ENABLE_MU=1"

28 January 2026

Schedule Choco Upgrade

If you are using Chocolatey, you probably want to keep installed software up to date. You can automate it with Task Scheduler (runs as SYSTEM, highest privileges). Run these commands from an elevated Command Prompt / PowerShell.

Always-on machines (weekly schedule):

schtasks /Create /F /RU SYSTEM /RL HIGHEST /SC WEEKLY /D SUN /ST 03:00 /TN "Choco Upgrade" /TR "cmd /V:ON /C echo ==== !DATE! !TIME! ====>> C:\ProgramData\ChocoUpgrade.log & choco upgrade all -y --no-progress >> C:\ProgramData\ChocoUpgrade.log 2>&1"

This works best on machines that are typically powered on at the scheduled time.

Laptops (run on startup, with a 5min delay):

schtasks /Create /F /RU SYSTEM /RL HIGHEST /SC ONSTART /DELAY 0005:00 /TN "Choco Upgrade" /TR "cmd /V:ON /C echo ==== !DATE! !TIME! ====>> C:\ProgramData\ChocoUpgrade.log & choco upgrade all -y --no-progress >> C:\ProgramData\ChocoUpgrade.log 2>&1"

Note: this runs on every startup (Chocolatey will usually finish quickly if there is nothing to upgrade).


14 May 2025

Search through all event logs for specific event using PowerShell

 In PowerShell you can search through all event logs for a specific phrase in event Message field

This is the oneliner for that

Get-WinEvent -FilterHashtable @{LogName = '*'; StartTime = (Get-Date).AddDays(-1) } | Where-Object Message -match 'checkpoint' | Out-GridView


14 November 2023

Last reboot reason using PowerShell

 Use this PowerShell command, to obtain last restart reasons:

$x = foreach ($e in (Get-WinEvent -FilterHashtable @{logname = 'System'; id = 1074 })) {

    [PSCustomObject]@{

        Time        = $e.TimeCreated

        Type        = $e.Properties.Value[4]

        User        = $e.Properties.Value[6]

        Process     = $e.Properties.Value[0]

        Reason      = $e.Properties.Value[2]

        Description = $e.Properties.Value[5]

    }

}

$x | Out-GridView


27 October 2023

Autofit Excel sheets constantly

While your Excel sheet open, press ALT+F11


and double-click on the Sheet1 to open the blank window


copy this code there

Private Sub Worksheet_Change(ByVal Target As Range)

    Me.Cells.EntireColumn.AutoFit

End Sub


and close the Visual Basic window.

If you make a change to a single cell, all the columns will automatically adjust their width



19 October 2023

Get-WmiObject works on PowerShell 7

 Yeah, a lot of people are saying that you cannot use Get-WmiObject in PowerShell 7 and you must use instead Get-CimInstance. Well, this is true and also not true.


I have PowerShell based WMI scanner to scan all servers in domain to discover disk free space. Some are older Windows versions and Get-CimInstance does not get result back, so I want to use Get-WmiObject -Computername instead.


To enable Get-WmiObject use this command:


Import-Module Microsoft.PowerShell.Management -UseWindowsPowerShell


After that your Get-WmiObject is working