Skip to content

Instantly share code, notes, and snippets.

Bryan Lockwood bklockwood

Block or report user

Report or block bklockwood

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View get-installedsoftware.ps1
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | `
Where-Object {$_.Displayname -ne $null } | `
Select-Object Publisher, DisplayName, DisplayVersion | `
Sort-Object Publisher | `
Format-Table -AutoSize `
@bklockwood
bklockwood / meminfo.ps1
Last active Jun 17, 2016
Memory diagnosis
View meminfo.ps1
#this works for win10; older windows may not have same-same wmi class members
$physmem = (Get-CimInstance Win32_PhysicalMemory | select BankLabel, DeviceLocator, Capacity, ConfiguredClockSpeed, Manufacturer, PartNumber | Format-Table -AutoSize)
$pfsettings = (Get-CimInstance Win32_PageFileSetting | Select-Object Name, InitialSize, MaximumSize | Format-Table -AutoSize)
$pfuse = (Get-CimInstance Win32_PageFileUsage | select Name, Status, CurrentUsage, PeakUsage | Format-Table -AutoSize)
$pfdiskuse = (Get-CimInstance Win32_PageFile | Select-Object Name, Status, Compressed, FileSize | Format-Table -AutoSize)
$diskdrives = (get-psdrive | ?{$_.Provider.Name -eq "FileSystem"} | Format-Table -AutoSize)
$autopf = (Get-CimInstance Win32_ComputerSystem).AutomaticManagedPagefile
if ($autopf -eq $true) {
Write-Output "Pagefile settings ARE DEFAULT (automatically managed)."
} else {
View win7-WU-bug.md

Brief overview of how Windows Update (WU) works, as I understand it:

  1. WU downloads a file called wsusscn2.cab from the MS content delivery network point nearest you. Depending on various network factors, this is usually completed within 10-60 seconds. (I have written a short script to manually verify this)
  2. The cab file is cryptographically signed. This signature is checked, and the cab is extracted. The cab contains more cabfiles, also crypto-signed. Their signatures are checked and they are extracted.
  3. These files are parsed against the live windows system to see which of the available updates actually need to be applied to this PC. WU tries to get is many patches into one 'install-and-reboot' operation as it can, but sometimes successive reboots will be needed.
  4. After the processing is complete, a list of eligible updates is displayed, and the user is asked to choose which ones to install.
  5. After user makes his/her choices and click the
View print-webpage.ps1
$IE = new-object -ComObject "InternetExplorer.Application"
$webpage = "http://bestforpuzzles.com/daily-quick-crossword/puzzles/2016-04/dq1-2016-04-06.html"
$IE.Navigate($webpage)
$IE.ExecWB(6,2)
@bklockwood
bklockwood / versioning-commands.ps1
Last active Mar 5, 2016
Version numbers in Win10 via PS
View versioning-commands.ps1
When WINVER says "Version 1511 (OS Build 10586.104)" ...
PS> (Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion').ProductName
Windows 10 Pro
PS> (Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion').ReleaseID
1511
PS> (Get-ItemProperty -Path 'HKLM:\Software\Microsoft\Windows NT\CurrentVersion').CurrentVersion
6.3
View gist:5a881b79f2c0947283da
From a fresh installed Windows 7 system, WU can take hours to deleiver the first list of updates. Some observations:
* If I use offlinewucheck (https://gist.github.com/bklockwood/716d9f582dd78a9e6e9e) on a VM, the download part (wsusscn2.cab) takes less
than a minute; local processing takes ~30 minutes.
* Others report hours. One person reported 23 hours, on an i7 with SSD and 12GB of RAM!
* Unpacking wsusscn2.cab requires a fair amount of crypto (sig checks) and produces THOUSANDS of files.
* I have hazy memory of it overwhelming 2GB systems. Never completes at all; produces 'low virtual memory' errors.
* A system with most updates applied completes the task quickly.
Experiments to run:
View HideLangPacks.ps1
function Get-UpdateList {
<#
.SYNOPSIS
Gets an ISearchResult containing updates from Windows Update.
.PARAMETER Computername
The target computer.
Cannot use an array of computernames here.
Defaults to the local PC.
View win7 icm issue.ps1
function test-remoteicm {
[CmdletBinding()]
Param ()
$true
write-output "hello"
}
@bklockwood
bklockwood / cim.ps1
Created Dec 18, 2015
Find CIM methods and parameters in powershell
View cim.ps1
PS C:\> $wumethods = gcls -Namespace ROOT/Microsoft/Windows/WindowsUpdate -ClassName MSFT_WUOperationsSession
PS C:\> $wumethods.CimClassMethods
Name ReturnType Parameters Qualifiers
---- ---------- ---------- ----------
SetCallerID UInt32 {CallerID} {implemented}
ApplyApplicableUpdates UInt32 {HResult} {implemented}
ScanForUpdates UInt32 {OnlineScan, SearchCriteria, HResult, Updates} {implemented}
ScanForUpdatesWithProxy UInt32 {BypassList, BypassLocal, ProxyAddress, SearchCriteria...} {implemented}
DownloadUpdates UInt32 {Updates, HResult} {implemented}
@bklockwood
bklockwood / Setup-PC.ps1
Last active Aug 7, 2019
Setting up a new PC
View Setup-PC.ps1
#Activate Windows
slmgr.vbs /ato
#Enable RDP (don't require Network Level Auth)
set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -Value 0
set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp' -name "UserAuthentication" -Value 0
Enable-NetFirewallRule -Name RemoteDesktop-UserMode-In-TCP
#Allow ping, v4 and v6
New-NetFirewallRule -Name Allow_Ping4 -DisplayName "Allow IPV4 Ping" -Protocol ICMPv4 -Enabled True -Profile Any -Action Allow
You can’t perform that action at this time.