Archive for the ‘Windows’ Category.

Linux – Retrieve Windows OEM/BIOS key

Most laptops come with Windows license, but if you run Linux variant as your primary OS, you can still use the Windows OEM activation in VirtualBox, kvm, or what ever virtualization tool you use.

To retrieve the product key in bios.

sudo xxd /sys/firmware/acpi/tables/MSDM

Key will show at the end of the output

Powershell – Enable TLS1.2 for Windows 7, 8, Server 2012 R2 or older

I prefix this line on all PowerShell scripts that I know will be running on older PCs. Needed for Send-MailMessage, Invoke-WebRequest, Invoke-RestMethod, and probably more.

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Windows 11 – TPM, RAM, Secure Boot bypass install restrictions.

Windows 11 has many system requirements that are ‘soft’ and not actually needed to function. During install you can disable of these checks. (RAM, TPM, Secure Boot, possibly more)

  1. Start Windows 11 install with boot media
  2. shift+10 to launch command prompt
  3. Launch regedit
  4. Go to HKEY_LOCAL_MACHINE\SYSTEM\Setup and make new key labeled “LabConfig”
  5. In LabConfig, add DWORD “BypassTPMCheck” with value 1 to disable TPM check
  6. In LabConfig, add DWORD “BypassRAMCheck” with value 1 to disable RAM Check (4GB Min)
  7. In LabConfig, add DWORD “BypassSecureBootCheck’ with value 1 to disable Secure Boot checking
  8. In LabConfig, add DWORD “BypassStorageCheck” with value 1 to disable disk check (64GB min)
  9. Close regedit and command prompt and continue install like normal. 

Windows 10 to Windows 11 in place upgrade, still use USB Install to start the upgrade.

  1. Start Windows 11 install with boot media
  2. shift+10 to launch command prompt
  3. Launch regedit
  4. Go to HKEY_LOCAL_MACHINE\SYSTEM\Setup and make new key labeled “MoSetup”
  5. In MoSetup, add DWORD “AllowUpgradesWithUnsupportedTPMOrCPU” with value 1
  6. Close regedit and command prompt and continue upgrade 

Alternatively, rufus has Windows 11 ISO download and bypass check built in.

Windows – Install Print Management Console

Some reason Print Management Console is not installed by default on Windows 10 Pro and Windows 11 Pro on recent builds. Has to be manually installed. New Windows 10 & 11 Settings for printer is just garbage in my opinion. Use Print Management for real control of printer and print drivers.

DISM /online /add-capability /CapabilityName:Print.Management.Console~~~~0.0.1.0

After it is installed it can ran by searching for “Print Management” or running “printmanagement.msc”

Windows – Add Group Policy to Home EditionĀ 

Sometime is easier to set policy/security change via windows Local Group Policy editor than to look up specific registry key. Windows Home edition doesn’t include it by default but it can be installed! Works on Windows 10 Home, have not attempted on Windows 11 Home.


FOR %F IN ("%SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientTools-Package~*.mum") DO (
 
DISM /Online /NoRestart /Add-Package:"%F"
 
)
 
FOR %F IN ("%SystemRoot%\servicing\Packages\Microsoft-Windows-GroupPolicy-ClientExtensions-Package~*.mum") DO (
 
DISM /Online /NoRestart /Add-Package:"%F"
 
)

Windows – Credential Manger via command line

You can store and recall password with Windows Credential manger. Great to enter saved password to be used within batch scripts.

Base command is: cmdkey

Documentation on microsoft’s website

For Powershell use CredentialManger module

https://www.powershellgallery.com/packages/CredentialManager/2.0

Powershell – Download a file

Invoke-WebRequest

Invoke-WebRequest -Uri https://example.com/files/myfile.exe -OutFile $env:USERPROFILE\Downloads\myfile.exe

Windows – Compress each file in folder into 7z archive. Keep modified date and delete original.

for /f %i in ('forfiles /D -12/31/2011 /c "cmd /c echo @FILE"') do @7z a Archives/%~i.7z %~i -mmt=on -sdel -stl
  • Command is to be ran at same folder you want to compress every file into a single 7z.
  • Forfiles /D will only select files older than specified date. 
  • It will place each 7z into Archives subfolder.
  • Keeps the date of the file inside as archive date.
  • “-sdel” Delete file when done.

Windows Powershell – Manage Printers and Printer Ports

Reference this documenation for more commands and options. This works only in Windows 10
https://docs.microsoft.com/en-us/powershell/module/printmanagement/?view=win10-ps

here are some example commands to add port, view printers, and update their port configurations. These are running from batch shell.

powershell -Command "Add-PrinterPort -Name "10.3.0.50" -PrinterHostAddress "10.3.0.50" -SNMP 1 -SNMPCommunity public"
powershell -Command "Add-PrinterPort -Name "10.3.0.51" -PrinterHostAddress "10.3.0.51" -SNMP 1 -SNMPCommunity public"
powershell -Command "get-printer"
powershell -Command "Set-Printer -Name CanonBW -PortName "10.3.0.51""
powershell -Command "Set-Printer -Name CanonColor -PortName "10.3.0.50""

Windows – Get files older than 7 days then delete them

Get-ChildItem 'C:\path\to\files'  | Where-Object {($_.LastWriteTime -lt (Get-Date).AddDays(-7))} | Remove-Item