22 June 2026

DPM Free Tape Threshold

By default, DPM may generate alerts when the number of free tapes in the library drops below the configured threshold. In my environment, the robotic library was configured to require at least two free tapes, which resulted in unnecessary warnings.

To disable this requirement and stop the alerts, set the free tape threshold to 0. Change the server1.fqdn to your dpm server fully qualified domain name and DPMDB_server1 to your actual DPM database name.

sqlcmd -S server1.fqdn -d DPMDB_server1 -E -Q "UPDATE tbl_MM_MediaPool SET MinThresholdForFreePool = 0 WHERE Type = 2"

Run this command in Administrative command prompt (or powershell). After running the command, DPM will no longer require free tapes to be present in the free pool and the related alerts will disappear.

The sample event I got (pasted it here for people searching the internet about how to get that event disappear)

Affected area: IBM Storage 3572 Tape Library
Occurred since: 22.06.2026 08:45:59
Description: The number of free tapes in the Tape Library IBM Storage 3572 Tape Library is less than or equals the threshold value of 1. You must add tape to the library and mark it as free in order to prevent future backups from failing. (ID 3305)
More information
Recommended action:
Add tape to the library and mark it as free.
Resolution: To dismiss the alert, click below
Inactivate

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

14 April 2023

Automatic update of Chocolatey packages

 If you are installed some software using https://chocolatey.org and want to keep it up to date, then open administrative Command Prompt (cmd.exe as administrator) and paste this line there:

schtasks /create /tn choco-update /tr "cup all -y" /sc daily /st 02:46 /ru SYSTEM /rl HIGHEST

This will create a scheduled task, which runs every day at 02:46 (nighttime) and updates all chocolatey packages (the command "cup all -y" does that).



To see all scheduled tasks, open taskschd.msc and see it for yourself:



To see log file, what actually has happened during last nightly sessions, open this file:

"C:\ProgramData\chocolatey\logs\chocolatey.log"



05 April 2023

Create CAA record using PowerShell in Windows DNS

 Because CAA records are not natively supported in Windows Server DNS service, then you need to do this manually. I created a PowerShell script for that:


$zone = 'yourdomain.com'

$provider = 'letsencrypt.org'

$caa = "00056973737565" + ([BitConverter]::ToString($provider.ToCharArray())).Replace("-", "")

Add-DnsServerResourceRecord -ZoneName $zone -Name '@' -Type 257 -RecordData $caa


This script must be executed in Windows Server, where DNS service is installed and contains your external DNS zone.

Your zone name must be written on the first line and your provider name must be on next line

To verify your CAA record in internet, search for CAA checker page and type there your domain name and hit the Check button.

08 August 2022

Read IIS log file using PowerShell

 Actually you need just few lines

$file = '\\iisserver\c$\inetpub\logs\LogFiles\W3SVC1\u_ex220808.log'
$headers = (Get-Content $file | Select-Object -Skip 3 -First 1).Split(' ') | Select-Object -Skip 1
$result = Import-Csv $file ' ' -Header $headers | Where-Object date -NotLike '#*'
$result | ConvertTo-Csv -Delimiter `t -NoTypeInformation | Set-Clipboard

Output will be in clipboard (in this case it will be with tab separated for easy pasting into Excel or similar)

21 June 2022

Resize partition using PowerShell

 Resize using this command line (PowerShell as Administrator):

Get-Partition -DriveLetter c | Resize-Partition -Size 96GB

21 February 2022

Start service on remote machine using PowerShell

If you just want remotely use mmc, then start services.msc and connect to remote computer

If you want to use PowerShell, use the following command (atagateway is one example service and serverX is example server name):

Get-Service atagateway -ComputerName serverX | Set-Service -Status running

If you have remote PowerShell enabled, then you can also use this command:

Invoke-Command serverX {Start-Service atagateway}

03 February 2022

Upload domain joined computer bitlocker key to Active Directory

To upload already encrypted drive bitlocker key to AD, you can use this PowerShell oneliner. Remember to use "run as administrator"

Backup-BitLockerKeyProtector c: ((Get-BitLockerVolume c:).KeyProtector | ? KeyProtectorType -eq RecoveryPassword).KeyProtectorId

If you already have the information in AD, then it doesn't hurt, it will not create any duplicates in AD


08 December 2021

Get all subnets in you Active Directory

 To get all subnets in your Active Directory, use this PowerShell oneliner:

[System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Sites.Subnets.Name

16 July 2021

Get Windows 10 saved WiFi passwords using PowerShell

I wrote an under-100-character oneliner for getting all saved WiFi passwords on Windows 10 computer:


netsh wl sh p|%{($_-split': ')[1]}|%{$_;netsh wl sh p n=$_ k=clear|%{($_-split'nt\s+: ')[1]};''}


Ouput will be in the format:


SSID (network name)
WPA key (network password)


Each combo will be separated with an empty line. If some WiFi networks haven't got password, then only SSID will be shown.



09 April 2021

Shrink WSUS database

I discovered, that WSUS database and log file are very huge (WSUS.mdf and WSUS_log.ldf). Here's what I did to reduce the size:

Facts:
1. WSUS uses Windows Internal Database
2. To do some command against this database engine, you need SQL server management studio
3. It's very easy to install SSMS using Chocolatey
4. It's very easy to install Chocolatey using powershell
5. PowerShell might need some adjustments

Actual To-Do list:
1a. install Chocolatey (open PowerShell as an administrator)
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
1b. install Chocolatey (open cmd as an administrator)
powershell -exe unrestricted "iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex"
2. If this command throws certificate error, please use his command before (also in PowerShell)
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12


3. Now open cmd.exe as Administrator and install SSMS
cinst sql-server-management-studio -y


4. Next thing is to open SSMS as system (you might need to restart computer before opening SSMS).
psexec -s -i cmd
and in the opened windows paste the path to the ssms executable
"C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Ssms.exe"


5. If you don't have psexec installed, use this line to install PSTools
cinst pstools -y


6. To connect to WID, you need to connect to this "server":
np:\\.\pipe\MICROSOFT##WID\tsql\query


7. To shrink all databases, use this query in the New Query window
EXEC sp_MSForEachDB 'select ''?'' as [Database]; ALTER DATABASE [?] SET RECOVERY SIMPLE; DBCC SHRINKDATABASE (''?'' , 0)'


Profit. 40GB more free disk space

06 November 2020

Invoke-Command and local variables in PowerShell

Just use "using:" before the variable name

$abc= 'some text'
icm servername {'----';echo $abc;'----'}
icm servername {'====';echo $using:abc;'===='}

Here we set the local variable with the name $abc to some value. When using Invoke-Command (alias icm), then first version uses remote version of that variable, which probably is empty and second version kinda drags the local variable to remote session and you can use it there.


 How to generate pronouncable password using PowerShell

Paste following two lines into an Administrative PowerShell and here you go:

Install-Module MlkPwgen -ErrorAction SilentlyContinue
New-PronounceablePassword -Digits



03 November 2020

 How to work with printers like PowerShell guru

If you are lost finding printer listing in Windows 10, just open powershell and type the following:

Get-Printer | ogv

If you want to delete one of them:

Get-Printer | ogv -PassThru | Remove-Printer

Just select one of them in the Out-Gridview window and press OK and it will be deleted