BigFont Blog
  • Home
  • About
  • Bibliography (Work)

powershell

A collection of 11 posts

Avoid Leaving PowerShell Side-Effects on the Pipeline
powershell

Avoid Leaving PowerShell Side-Effects on the Pipeline

In the unrelated picture, look, I have started to learn how to draw! This evening, I dug myself out of a PowerShell trap that has caught me dozens of times: leaving values on

  • Shaun Luttin
    Shaun Luttin
1 min read
powershell

PowerShell: List TCP Connections for a Process

Get-Process -Name testhost | ForEach-Object { Get-NetTCPConnection -OwningProcess $_.Id -State Established; } | Select-Object -First 50 -Property CreationTime, OwningProcess, LocalPort, State, RemoteAddress | Sort-Object LocalPort | Format-Table

  • Shaun Luttin
    Shaun Luttin
1 min read
Check whether two C# builds result in binaries that are functionally identical (within reasonable limits).
powershell

Check whether two C# builds result in binaries that are functionally identical (within reasonable limits).

I spent some of my weekend determining whether the IL changed between builds. The following script builds a solution, generates intermediate language from the build result, filters out stuff that always changes (such

  • Shaun Luttin
    Shaun Luttin
1 min read
powershell

How to use PowerShell to release a locked Windows port?

Let's say we want to release port 8081 (and we do not want to restart our computer). First, find the Process ID that is using the port. The easy way: Get-Process -Id (Get-NetTCPConnection

  • Shaun Luttin
    Shaun Luttin
1 min read
List all the keyboard shortcuts that are available in PowerShell.
powershell

List all the keyboard shortcuts that are available in PowerShell.

From within PowerShell, run the following commandlet: Get-PSReadLineKeyHandlerThat prints all the key bindings that are available out-of-the-box in PowerShell Desktop 5.1 and PowerShell Core 7.1. Some of them are more like

  • Shaun Luttin
    Shaun Luttin
4 min read
powershell

PowerShell One-Liner: insert a space between each capital letter; convert PascalCase to Pascal Case

PS> ('FooBar' -creplace '([A-Z])', ' $1').Trim() Foo Bar

  • Shaun Luttin
    Shaun Luttin
1 min read
git

PowerShell and Git to Capitalize all the Files in a Directory on Windows

Windows is a case-folding operating system, which means that changing the case of a file name is non-trivial. The following uses PowerShell and Git to capitalize all the files names in a directory.

  • Shaun Luttin
    Shaun Luttin
1 min read
Trim Trailing Whitespace from All Files in a Directory
powershell

Trim Trailing Whitespace from All Files in a Directory

This one liner trims trailing whitespace from every file in the current directory. dir -rec -file | % { $t = $_ | gc | % { $_.TrimEnd() }; sc $_.FullName $t; } Annotated Version: Note that in the outer loop $_ refers to the

  • Shaun Luttin
    Shaun Luttin
1 min read
powershell

Permanently modify an environmental variable from PowerShell

For instance, here we are adding to the PATH. PS> $addMe = "C:\utilities"; PS> [Environment]::SetEnvironmentVariable("PATH", $env:Path + ";" + $addMe, [System.EnvironmentVariableTarget]::Machine); This also

  • Shaun Luttin
    Shaun Luttin
1 min read
Powershell: Trim trailing whitespace from all files recursively
powershell

Powershell: Trim trailing whitespace from all files recursively

One Line: ls -r *.cs | % {(gc $_ | % { $_.TrimEnd() }) | sc $_ } Multiple Lines (same command): Get-ChildItem -Recurse *.cs | ForEach-Object { (Get-Content $_ | ForEach-Object { $_.TrimEnd() }) | Set-Content $_ } Note that we're filtering for files with a *.cs extension. To include all

  • Shaun Luttin
    Shaun Luttin
1 min read
asp.net-core

Use PowerShell to inspect project.json properties across directories

Get the Member: Inspect buildOptions: dir -Recurse project.json | % { gc -Raw $_ | convertfrom-json | gm buildOptions } Inspect runtimes: dir -Recurse project.json | % { gc -Raw $_ | convertfrom-json | gm buildOptions } Select the Member: Inspect buildOptions: dir -Recurse project.

  • Shaun Luttin
    Shaun Luttin
1 min read
BigFont Blog © 2022
Latest Posts Ghost