Author Archive

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

Windows – Set various power settings via command line

Set various timeout setting for sleep, hibernate, disk, and monitor. Below will disable all timeouts. Great for VM workstations that need to run 24/7

powercfg /x -hibernate-timeout-ac 0
powercfg /x -hibernate-timeout-dc 0
 
powercfg /x -disk-timeout-ac 0
powercfg /x -disk-timeout-dc 0
 
powercfg /x -monitor-timeout-ac 0
powercfg /x -monitor-timeout-dc 0
 
Powercfg /x -standby-timeout-ac 0
powercfg /x -standby-timeout-dc 0

Powershell – Download a file

Invoke-WebRequest

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

Powershell – Install RAST (Remote Server Administration Tools)

These tools can be install on any workstation to administrate servers remotely. Command below will install all Window Server tools

Get-WindowsCapability -Online |? {$_.Name -like "*RSAT*" -and $_.State -eq "NotPresent"} | Add-WindowsCapability -Online

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 AD – Get list of computers in domain

Get-ADComputer -filter * | select name | ft

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

Windows – Test AD Credentials in Powershell

Function Test-ADAuthentication {
    param($username,$password)
    (new-object directoryservices.directoryentry "",$username,$password).psbase.name -ne $null
    }
 
 
Test-ADAuthentication "dom\myusername" "mypassword"