Account

Posts of Windows OS Hub for SysAdmins

newest first

#499Photo

📚 The OSLicense module is a new built-in PowerShell module designed to manage Windows activation, intended to supersede the legacy slmgr.vbs script. As we mentioned previously, Microsoft has deprecated the VBScript engine in Windows and it is expected to be removed from the OS in upcoming releases over the next couple of years.  Therefore, existing VBScript scripts will gradually be replaced by PowerShell equivalents or WMI classes. In the September updates for Windows 11, a new PowerShell module called OSLicense was added. It is designed to supersede the well-known slmgr.vbs script, which has served as the primary command-line tool for managing Windows licensing and activation for over two decades. Check whether the module is installed on the computer: Get-Module -ListAvailable -Name OSLicense Check your Windows license type and its activation status: Get-OSLicenseInfo | Select Name, Version, LicenseStatus, Description   Let's look at how to manually activate Windows against a KMS server using the OSLicense module. Install a GVLK product key for you Windows version: Invoke-OSLicense -InstallProductKey "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" Specify the KMS server address and port: Set-KmsLicenseInfo -ServerName kms1.woshub.com -Port 1688 Activate Windows on the specified KMS server: Invoke-OSLicense -ActivateOnline 📝System administrators can now proactively audit their environment for dependencies and search for scripts, MDT/SCCM task sequences, Intune/RMM automation and Group Policy scripts containing slmgr.vbs or cscript calls, and begin migrating their automation logic to the modern PowerShell cmdlets. When Microsoft disables VBScript Feature on Demand (FoD) component by default around 2027 (Phase 2 of deprecation), slmgr.vbs will stop working out of the box because it is a VBScript file. Any scripts, task sequences, or helpdesk procedures that call slmgr.vbs will fail. 📌 The post covers how OSLicense cmdlets correspond to slmgr.vbs options, along with typical usage examples, including installing and uninstalling a Windows product key, checking license status, KMS and offline activation. 📚 PowerShell OSLicense Module: Manage Windows Activation Without slmgr.vbs

Open in Telegram
Views224−43%vs avg
Forwards—
Reactions9
Comments—
#498Photo

🔥 By default, the built-in Windows Firewall doesn’t log dropped packets or successful network connections. If you suspect that the Windows Firewall is blocking connections to a specific port or IP address, you can enable firewall logging to identify the issue without disabling the firewall completely. Let’s look at how to enable logging of rejected (DROP) connections, find the connection attempts in the logs (source and port), and create the appropriate allow rule. 🧱 ☑️ The following PowerShell command configures Windows Defender Firewall to log blocked network traffic for the Public profile to a plain text file: Set-NetFireWallProfile -Profile Public -LogBlocked True -LogMaxSize 20480 -LogFileName "%systemroot%\system32\LogFiles\Firewall\pfirewall.log" -Verbose ☑️ Or you can send the network connection logs to the Windows Event Viewer. This can sometimes be more convenient than grepping plain text files. To do this, enable the following audit policy: Auditpol /set /category:"System" /SubCategory:"Filtering Platform Packet Drop" /failure:enable   Then you can use the following PowerShell function to analyze firewall log files, which presents the log as a convenient graphical table using Out-GridView.  function Get-WindowsFirewallLog { param( [parameter(Position=0,Mandatory=$false)] [ValidateScript({Test-Path $_})] [string]$LogFilePath = "$env:SystemRoot\System32\LogFiles\Firewall\pfirewall.log" ) $headerFields = @("date","time", "action","protocol","src-ip","dst-ip","src-port","dst-port","size", "tcpflags","tcpsyn", "tcpack","tcpwin","icmptype","icmpcode", "info","path") $firewallLogs = Get-Content $LogFilePath | ConvertFrom-Csv -Header $headerFields -Delimiter ' ' $firewallLogs | Out-GridView } Get-WindowsFirewallLog ✅ This guide explains how to enable Windows Firewall logging and the basic methods for searching and analyzing firewall logs. 📖 How to Enable and Analyze Windows Firewall Logs

Open in Telegram
Views216−45%vs avg
Forwards—
Reactions9
Comments—
#497Photo
Views246−37%vs avg
Forwards—
Reactions9
Comments—
#496Link preview
Views410+4%vs avg
Forwards—
Reactions11
Comments—
#495Photo
Views402+2%vs avg
Forwards—
Reactions11
Comments—
#494Photo

Safe Cleanup of C:\Windows\Installer Folder: Find Orphaned MSI and MSP Files 🛠 One of the common causes of running out of free space on the system drive in Windows is the C:\Windows\Installer folder. Over time, it can grow to dozens of gigabytes. This folder contains the system cache for packages installed through the Windows Installer service, including cached copies of installers in the .MSI format, as well as their update packages (.MSP format). The msiserver automatically caches installation packages to the %windir%\Installer directory when applications are installed or updated, even if the installation is subsequently cancelled. These cached copies of MSI installation files allow you to safely uninstall, repair, or modify installed Windows apps, even if the source installation files have been deleted. During a standard program uninstallation, MSI and MSP files in this folder should be removed automatically. In practice, orphaned packages often remain as a result of interrupted installations, the use of third-party uninstallers, or outdated versions being left behind after updates. ⚠️ The key point to remember is that you should never manually delete files from %windir%\Installer without thinking. You might run into issues when trying to uninstall or repair installed apps properly if you don't have cached MSI and MSP packages. ✅ We have a ready-to-use PowerShell script in our GitHub repository that queries the Windows Installer service for the list of registered packages and compares it with the files physically stored in C:\Windows\Installer. Any MSI/MSP files that exist on disk but are missing from the msiexec database are considered orphaned. The script implements the same logic as the popular third-party PatchCleaner tool. You can download this PowerShell script here. The script only lists orphaned MSI and MSP packages that are no longer associated with any installed program. It does not remove anything. Download and run the script: Set-ExecutionPolicy RemoteSigned -Scope Process .\Get-OrphanedMSIInstallers.ps1 In my case, the script found several orphaned MST patches for Adobe Acrobat Reader. These were taking up about 7 GB of space. 📚 How to Properly Clean Up the Windows Installer Folder

Open in Telegram
Views513+31%vs avg
Forwards—
Reactions15
Comments—
#493Photo

How to Shrink WSL2 or Docker Desktop VHDX Files in Windows 11 🐧 When using Windows Subsystem for Linux (WSL2), the Linux distribution's virtual disk file (ext4.vhdx) can grow to tens of gigabytes. However, deleting files inside the WSL distro environment doesn’t automatically reduce the size of the VHDX file on the Windows filesystem. Dynamic VHDX files can grow as new data is written to them, but they do not automatically shrink when data is deleted inside the virtual disk from within the guest OS. ⚠️ For example, the ext4.vhdx file on the Windows system drive might occupy 50 GB, even though only 3 GB is actually being used inside WSL. These VHDX files can be manually compacted offline. 📌 To check how much space is actually being used inside WSL image: df -h / To find the path to your WSL distribution's VHDX file, first list all installed WSL distributions: wsl.exe --list –verbose Then retrieve the virtual disk information for the specified WSL image from the registry: $distro='Ubuntu-26.04' $vhdx=(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq $distro}).GetValue("BasePath") + "\ext4.vhdx" Stop the running WSL instance: wsl --shutdown Compact the VHDX file using PowerShell: Optimize-VHD -Path "..\fullpath\ext4.vhdx" -Mode Full Or using diskpart: select vdisk file="..\fullpath\ext4.vhdx" attach vdisk readonly compact vdisk detach vdisk Similarly, you can compact the Docker Desktop VHDX file after removing any unused images and containers. Optimize-VHD -Path "$env:LOCALAPPDATA\Docker\wsl\disk\docker_data.vhdx" -Mode Full 📚 In this article, we'll explore where WSL and Docker Desktop VHDX disks are stored, how to determine actual disk space usage, clean up data, and reduce the size of virtual disks using Optimize-VHD or diskpart. It also covers the experimental WSL2 sparse mode, which can automatically return unused space to the host system. How to Shrink a WSL2 or Docker Desktop Virtual Disk in Windows

Open in Telegram
Views434+11%vs avg
Forwards—
Reactions7
Comments—
#492Photo
Views411+5%vs avg
Forwards—
Reactions13
Comments—
#491Photo
Views553+41%vs avg
Forwards—
Reactions13
Comments—
#490Photo

👥 In large enterprise environments, where the same infrastructure servers can be managed by multiple administrators or support teams, it sometimes happens that someone accidentally removes a specific app or agent from a management host. To investigate such incidents and identify the exact user who installed or uninstalled a specific app, you can search for the app installation and removal events in the Windows Event Viewer.   📝 Events relating to the installation or removal of classic Windows apps via the MSI installer are logged in the Event Viewer: 📥 11707 – event code for successful installation of the MSI application. 🗑 11724 – event code for uninstalling the MSI-based app   You can open the Event Viewer log console (eventvwr.msc) and enable filtering for event IDs 11707 and 11724 for the Application log, or use a simple PowerShell script to find the related events. For example, the following PowerShell script returns information about who installed or uninstalled the Zabbix agent on a Windows host and when this occurred: $app_name='*Zabbix*' Get-WinEvent -FilterHashtable @{LogName="Application"; ID=11707,11724; ProviderName='MsiInstaller'}| Where-Object { $_.Message -like $app_name }| Select TimeCreated, @{Name='Username'; Expression={(New-Object System.Security.Principal.SecurityIdentifier($_.userid)).Translate([System.Security.Principal.NTAccount]).Value}}, Message   How to Detect Which User Installed or Removed a Program on Windows using Event Viewer

Open in Telegram
Views518+32%vs avg
Forwards—
Reactions15
Comments—
#489Photo
Views632+61%vs avg
Forwards—
Reactions14
Comments—
#488Link preview
Views676+72%vs avg
Forwards—
Reactions11
Comments—
#487Photo

Set Up SSH Key Authentication for Windows OpenSSH 📟 The built-in OpenSSH server in Windows supports SSH key-based authentication, enabling you to perform remote logins without entering a password, which is useful for performing various remote administration and automation tasks. To set it up, generate an SSH key pair on the client machine as usual. Then, add the public key to the authorized_keys file on the Windows machine running the OpenSSH server. However, there’s a Windows-specific quirk that often catches administrators out: the location of the authorized_keys file depends on whether or not the user is a member of the local Administrators group. ⚠️ On Windows, the location of the file containing the public keys depends on the account's privileges. The default locations differ: 🔹 Regular (non-admin) users: C:\Users\%username%\.ssh\authorized_keys 🔹 Members of the local Administrators group: C:\ProgramData\ssh\administrators_authorized_keys The following option in the sshd_config file enables this behaviour by default: Match Group administrators     AuthorizedKeysFile __PROGRAMDATA__/ssh/administrators_authorized_keys If you comment out this block in sshd_config, the override no longer applies. Unless a different location is specified in another sshd option, OpenSSH will use the standard ~/.ssh/authorized_keys file in the user's profile,  including for local administrators. 📚 The article covers configuring key-based SSH authentication on Windows 10/11 and Windows Server, including: ✅ Generating SSH keys on the client machine ✅ Adding public keys on a Windows host running the OpenSSH server ✅ Configuring the sshd_config file on the server side ✅Auditing OpenSSH auth logs   How to Configure SSH Key-Based Authentication in Windows

Open in Telegram
Views623+59%vs avg
Forwards—
Reactions8
Comments—
#486Link preview
Views669+70%vs avg
Forwards—
Reactions14
Comments—
#485Photo

📚 Rclone on Windows: Automate backup and sync files with Google Drive and other cloud storage providers. As an alternative to official cloud clients, you can use Rclone a small command-line tool often described as rsync for the cloud. It supports Google Drive and many other cloud storage providers, including S3-compatible object storages, allowing you to automate the synchronization of local folders with the cloud using scripts. Install Rclone on Windows using winget: winget install Rclone.Rclone Run the interactive configuration wizard to connect to Google Drive: rclone config One-way folder copying to cloud storage: rclone copy "C:\Backup" gdrive:MyPCBackup --progress Mirror a local directory to a cloud (one-way sync). This makes the destination identical to the source by copying new files and deleting removed ones: rclone sync "C:\Backup" gdrive:MyPCBackup --progress ⚠️ Be careful with sync! If you delete a file from the source directory, it will also be deleted from the cloud during synchronization. If you want to use the copy in the cloud storage as a backup, consider using the --backup-dir option to move older versions of modified or deleted files into an archive. 💡 What else can you do with Rclone? 🔹 Automate cloud backups with simple scripts 🔹 Mount cloud storage as a regular network drive with a drive letter assigned (WinFSP required). 🔹 Migrate data between cloud providers 🔹 Encrypt files transparently before uploading them to cloud using the rclone crypt command Rclone, unlike official cloud clients, doesn't sit in the system tray and consume system resources. It is highly versatile, makes switching cloud providers easier, and is ideal for scripting and automation tasks. 📚 The article covers Rclone installation and configuration on Windows, how to connect to cloud storage (Google Driver in this example), using copy and sync commands, scheduled backups, and data encryption. It also includes a simple PowerShell script that: 🔹 Syncs selected local folders with Google Drive 🔹 Copies deleted and modified files to the cloud archive 🔹 Automatically removes old file versions 🔹 Runs on a schedule via Windows Task Scheduler ✅ rclone on Windows: Sync and Backup Files to Google Drive and Other Clouds

Open in Telegram
Views718+83%vs avg
Forwards—
Reactions11
Comments—
#484Photo
Views622+58%vs avg
Forwards—
Reactions13
Comments—
#483Photo

⌨️ The built-in Windows Keyboard Filter feature allows administrators to prevent users from using specific keyboard shortcuts. This can be useful for devices operating in kiosk mode, as well as for operator workstations, terminals and other computers with restricted user interfaces. For example, you can deny the use of standard keyboard shortcuts such as Alt+Tab, Alt+F4, Ctrl+Alt+Del, Ctrl+Shift+Esc, Ctrl+C/Ctrl+V, as well as custom key combinations or individual keys.   This feature can be installed using the following PowerShell command: Enable-WindowsOptionalFeature -Online -FeatureName Client-KeyboardFilter The registry key HKLM\SOFTWARE\Microsoft\Windows Embedded\KeyboardFilter contains a list of predefined Windows keyboard shortcuts. To block one of them, simply change the value of the corresponding registry item to Blocked.   To block the Alt+Tab shortcut, for example, change this registry entry: reg add "HKLM\SOFTWARE\Microsoft\Windows Embedded\KeyboardFilter" /v "Alt+Tab" /t REG_SZ /d "Blocked" /f A custom key combination can be added under CustomFilters: reg add "HKLM\SOFTWARE\Microsoft\Windows Embedded\KeyboardFilter\CustomFilters" /v "Ctrl+C" /t REG_SZ /d "Blocked" /f An individual key can be blocked by its scan code. For example, to block the left Windows key: reg add "HKLM\SOFTWARE\Microsoft\Windows Embedded\KeyboardFilter\CustomScancodes" /v "E05B" /t REG_SZ /d "Blocked" /f 📚 The article also covers how to create custom filters for individual keys and combinations, block keys by scan code, and check active policies using Event Viewer and PowerShell. ⚠️ Unfortunately, Keyboard Filter is only supported in the Enterprise, Education, IoT Enterprise and LTSC editions of Windows. Also, the filter does not work in RDP sessions. How to Block Specific Keyboard Shortcuts in Windows with Keyboard Filter

Open in Telegram
Views710+81%vs avg
Forwards—
Reactions13
Comments—
#482Link preview
Views713+82%vs avg
Forwards—
Reactions14
Comments—
#481Photo
Views686+75%vs avg
Forwards—
Reactions18
Comments—
#480Photo

🕐 Resource-intensive jobs in Windows launched via Task Scheduler can run significantly slower than when started manually. I encountered an issue with a Robocopy backup task launched via Task Scheduler on a high-load server. The scheduled task failed to complete overnight, but it finished in just a couple of hours when the backup script was run manually. The reason: by default, Windows Task Scheduler creates tasks with priority 7 (Below Normal). As a result, on high-load hosts, processes launched by Task Scheduler receive less CPU time than processes running at normal priority. ⚙️ The classic way to change a scheduled task's priority, which works on all versions of Windows, is to export the task to an XML file, open the file in a text editor, and change the Priority value from 7 (the default for all Task Scheduler tasks) to either  5 (Above Normal) or 6 (Normal). Then, the original task needs to be deleted and re-imported from the XML file with the new settings. However, if the task's settings are later changed through the graphical taskschd.msc console, its priority will be reset to its original value (7). ⚙️ Change the task priority with PowerShell ✅ Therefore, it is better to use the PowerShell cmdlets from the built-in ScheduledTasks module to change task priorities. Check the current task priority: $myTask = "py_Inspect" (Get-ScheduledTask -TaskName $myTaskName).Settings.Priority Set it to 5 (Above Normal): Set-ScheduledTask -TaskName $myTask -Settings (New-ScheduledTaskSettingsSet -Priority 5) 📖 How to Set Task Priority in Windows Task Scheduler

Open in Telegram
Views794+102%vs avg
Forwards—
Reactions12
Comments—