One-liners

Git

“Prune” the list of local tags

Cleans-up the list of local tags and synchronize it with remote (removes the tags that are not present anymore and adds any missing):

git tag -l | xargs git tag -d && git fetch -t

Count changed lines between two commits

Counts number of added and removed lines in a range between two commits:

git log --numstat --pretty=oneline .. | awk 'NF==3 { added += $1; removed += $2} END { printf(" * New lines: %d\r\n * Old lines: %d", added, removed)}'

Windows Registry

Identify which Uninstall key is for a given product

Displays the key name of the Uninstall registry which is responsible for a product with a given Display Name (as visible in Add/Remove Programs):

("HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall" | Get-ChildItem | Where-Object { $_.GetValue("DisplayName") -eq "<Product Name>" }).Name | Split-Path -Leaf

Miscellanous

Unblock all files

Start the following script in a folder containing files that are locked by Attachment Manager (for example untrusted files downloaded from internet or other high-risk zone) – the script unblocks all files at once.

Get-ChildItem -Recurse | Where-Object { !$_.PsIsContainer } | Unblock-File

Create a new self-signed certificate (for EXE/MSI/MSIX signing)

The following script generates three files – .pfx, .cer containing the private key and the certificate data, together with a password written to a text file.

$publisher = "CN=<YourName>";
$friendlyName = "<Your friendlyName>"
$password = "<YourPassword>"
$targetFolder = Join-Path -Path $PSScriptRoot -ChildPath "Generated";
$certName= "<FileNameWithoutExtension>"
 
if (-not (Test-Path $targetFolder))
{
    New-Item $targetFolder -ItemType Directory | Out-Null;
}

$pfxName= Join-Path -Path $targetFolder -ChildPath "$certName.pfx";
$cerName= Join-Path -Path $targetFolder -ChildPath "$certName.cer";
$pwdName= Join-Path -Path $targetFolder -ChildPath "$certName.pass";
 
$cert = New-SelfSignedCertificate -Type Custom -Subject $publisher -KeyUsage DigitalSignature -FriendlyName $friendlyName -CertStoreLocation "Cert:\CurrentUser\my";
$securePassword = ConvertTo-SecureString -String $password -Force -AsPlainText;
$cert | Export-PfxCertificate -FilePath $pfxName -Password $securePassword | Out-Null;
$cert | Export-Certificate -Type CERT -FilePath $cerName | Out-Null;
$password | Out-File $pwdName;
Remove-item $cert.PSPath;