08 December 2021

Get all subnets in you Active Directory

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


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:

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:
1. install Chocolatey (open PowerShell as an administrator)
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":

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

14 November 2019

How to install Adobe Reader using command line

First you need to open powershell as admin by pressing Windows+X and then A.

In the powershell prompt type following:

iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

This will install chocolatey software management utility.

Open next powershell window using the same Windows+X, A shortcut and type:

cinst adobereader -y

This will install Adobe Reader to your system.

To list, what software has been installed using chocolatey, use this command:

clist -l

To get more information about chocolatey, go to web site https://chocolatey.org/