PowerShell cover

GNU Coreutils to PowerShell Equivalents

If you’ve spent years on Linux and are now working on Windows, or you’re writing cross-platform documentation and need the PowerShell counterpart for a Unix command, this is the reference page for that. The tables below cover all major GNU Coreutils commands organized by category. Direct equivalents show the cmdlet and any aliases. For commands with no native equivalent, the closest workaround or recommended tool is noted. File Content Coreutils Purpose PowerShell Equivalent cat Concatenate/print files Get-Content (aliases: gc, cat, type) tac Print file in reverse (Get-Content file)[-1..-((Get-Content file).Count)] head Print first N lines Get-Content -TotalCount N / Select-Object -First N tail Print last N lines Get-Content -Tail N od Dump file in octal/hex Format-Hex xxd Hex dump Format-Hex wc Count words/lines/chars Measure-Object -Line -Word -Character nl Number lines $n=1; Get-Content f | % { "$n`t$_"; $n++ } pr Paginate text for printing No direct equivalent fold Wrap long lines No direct equivalent fmt Simple text formatter No direct equivalent Examples: ...

May 10, 2026
PowerShell cover

PowerShell: Close a Process Without Killing It

Stop-Process kills a process immediately, with no chance to save open files. For GUI applications (Notepad, Word, browsers), the right approach is to send a close signal to the main window, which is equivalent to clicking the X button: # The application receives a `WM_CLOSE` message and can handle it normally. # Output: True (Get-Process Notepad).CloseMainWindow() What the Return Value Means CloseMainWindow() returns True if the close message was delivered successfully. A True return means the message was delivered, not that the process has exited. The process may still be running while it handles the close (e.g., waiting for user input on a “save changes?” dialog). ...

May 10, 2026
PowerShell cover

PowerShell: Get DLL Info

When you encounter an unfamiliar .dll on your system (or want to confirm exactly which version of a library is installed), PowerShell can pull the embedded metadata out of the file without any third-party tools. The information is the same as what Windows shows in the Details tab when you right-click a file and open Properties. The Script Save this as Get-DllInfo.ps1: param([Parameter(Mandatory)][string]$Path) function Get-DllInfo { param( [Parameter(Mandatory)][string]$DllPath ) $fileInfo = Get-Item $DllPath $versionInfo = $fileInfo.VersionInfo $dllProperties = [PSCustomObject]@{ "File Description" = $versionInfo.FileDescription "Type" = $versionInfo.FileType "File Version" = $versionInfo.FileVersion "Product Name" = $versionInfo.ProductName "Product Version" = $versionInfo.ProductVersion "Copyright" = $versionInfo.LegalCopyright "Size" = $fileInfo.Length "Date Modified" = $fileInfo.LastWriteTime "Language" = $versionInfo.Language "Original Filename" = $versionInfo.OriginalFilename } $dllProperties | Format-List } Get-DllInfo -DllPath $Path Run it by passing a path to any DLL: ...

May 10, 2026
PowerShell cover

PowerShell: Rename File Extensions in Bulk

Renaming every .txt to .md, or every .jpeg to .jpg — PowerShell can do this in one line without any loops. Here are the patterns, from the simplest to the most flexible. The One-Liner Get-ChildItem -File | Rename-Item -NewName { $_.Name -replace '\.txt$', '.md' } This renames every file in the current directory whose name ends in .txt, changing the extension to .md. Files with other extensions are left unchanged. Breaking it down: Get-ChildItem -File — lists files only (no subdirectories). Rename-Item -NewName { ... } — the script block receives each file object as $_ and returns the new name. $_.Name -replace '\.txt$', '.md' — the -replace operator uses a regex. The \. escapes the dot (a bare . in regex means “any character”), and $ anchors the match to the end of the string so it only touches the extension. Preview Before Renaming Add -WhatIf to do a dry run — PowerShell prints what it would rename without touching anything: ...

May 10, 2026
Tools cover

Open Any File with fzf

fzf is a fuzzy finder for the terminal. Run it and you get an interactive list you can filter by typing. Select an entry and it prints the result to stdout. That makes it a composable building block. Pipe anything into it, use the output in any command. The simplest use case: open a file. Install fzf winget install junegunn.fzf Open a file with its default app & $(fzf) fzf walks the current directory recursively, shows you the files, and you pick one. The & call operator invokes whatever path comes back. On Windows this triggers the default file association, so .py opens in your IDE, .docx opens in Word, and so on. ...

May 9, 2026
PowerShell cover

PowerShell: Count Word Frequency

Count word occurrences in a text file with a single PowerShell pipeline: (Get-Content .\words.txt) -Split '\W+' | Group-Object | Sort-Object -Descending Count | Select-Object Count, Name Example output: Count Name ----- ---- 12 the 9 a 7 to 5 PowerShell 3 file How It Works Get-Content .\words.txt Reads the file as an array of lines. -Split '\W+' Splits each line on one or more non-word characters (\W+ matches spaces, punctuation, newlines, etc.), producing an array of individual words. ...

May 9, 2026
PowerShell cover

PowerShell: Replace Part of a File Name in Bulk

Need to rename report-2024.pdf to report-2025.pdf for every file in a folder? Or swap spaces for hyphens across a whole directory? PowerShell handles this in a single line. The One-Liner Get-ChildItem -File | Rename-Item -NewName { $_.Name -replace "2024", "2025" } This renames every file in the current directory, replacing the first match of 2024 with 2025 in the file name. Files that don’t contain 2024 are left alone. Breaking it down: Get-ChildItem -File — lists files only (no subdirectories). Rename-Item -NewName { ... } — the script block receives each file as $_ and returns the new name. $_.Name -replace "2024", "2025" — performs the substitution on the file name. Practical Examples Replace spaces with hyphens: ...

May 9, 2026
PowerShell cover

PowerShell: Sort an Array

Pipe any array to Sort-Object (alias: sort) to sort it: $a = 'k', 'a', 'z' $a | sort Output: a k z You can also sort inline without a variable: 'k', 'a', 'z' | sort Numbers PowerShell infers the correct numeric sort automatically: $n = 10, 3, 25, 1 $n | sort 1 3 10 25 Without Sort-Object, a lexicographic sort would put 10 before 3. Piping numbers through sort avoids that. Descending Order Pass -Descending to reverse the order: ...

May 9, 2026
PowerShell cover

PowerShell: View and Convert Markdown Natively

PowerShell has two built-in cmdlets for working with Markdown files. No external tools required. Show-Markdown Show-Markdown renders a Markdown file directly in the terminal with color formatting: Show-Markdown .\README.md Headings, bold, italic, code blocks, and lists are all styled using VT100 escape sequences. It reads the file and prints formatted output inline. You can also pipe a string: "This is **bold**." | Show-Markdown Open in the Browser Pass -UseBrowser to render the Markdown as HTML and open it in your default browser: ...

May 9, 2026
Tools cover

Search Inside DOCX Files with ripgrep and pandoc

DOCX files are binary ZIP archives and rg can’t search them directly. The fix is to pipe each file through pandoc, which converts DOCX to plain text (or Markdown) on the fly before rg searches it. Prerequisites Install both tools if you don’t have them: winget install BurntSushi.ripgrep.MSVC winget install JohnMacFarlane.Pandoc Search all DOCX files recursively Get-ChildItem *.docx -Recurse | % { echo "---" echo $_.Name pandoc $_.FullName -t markdown | rg -i 'my search string' } Argument Meaning *.docx Glob pattern, match only .docx files -Recurse Walk subdirectories recursively % Alias for ForEach-Object, runs the block for each file $_.FullName Full absolute path of the current file (required by pandoc) -t markdown Tell pandoc to output Markdown; preserves heading structure so you can see where in the document a match falls -i Case-insensitive search in ripgrep 'my search string' The search query (use single quotes in PowerShell to prevent string interpolation) Show context around matches Use -C to print lines before and after each match: ...

May 3, 2026
Tools cover

jq: Validate JSON

Quick tip today. I wanted to validate my JSON file with jq. jq can read files directly rather than requiring piped input, which is useful for large files. jq has the ability to read the file directly, which is great if your json file is large. By default jq prints out the loaded file. However, we use empty to not display any output. By default if there are any errors in the json file jq will output where the error is. ...

October 28, 2024
PowerShell cover

PowerShell: How to Create a File with Random Data

Generating random data into a file is important task that can be accomplished in PowerShell. Generating random data is useful for benchmarking reading and writing files. We will also do it fast! We can generate 1GB of random data into a file in about 800 ms. ⚠️ Do not use System.Security.Cryptography.RNGCryptoServiceProvider as it is obsolete, instead use System.Security.Cryptography.RandomNumberGenerator. System.Security.Cryptography.RandomNumberGenerator is good as we don’t have to create a new object and can use the static methods. ...

October 23, 2024
PowerShell cover

PowerShell: Output CSV From Two or More Arrays

The other day had created two arrays with the same length and I wanted to output them as columns in a CSV file. I couldn’t find an exact cmdlet to do this so I wrote a small script. Let’s get started. If you have two arrays such as: $arr1 = 'a', 'b', 'c', 'd' $arr2 = 1 , 2 , 3 , 4 I want to output the two arrays into a CSV such as each array is a column: ...

October 14, 2024
PowerShell cover

PowerShell: While Loop

PowerShell has verstile scripting language which includes different kinds of loops. The while loop is a common looping syntax found in different langauges. The basic syntax for a while loop is: while ( <Condition> ) { # Code } We can convert from a for loop to a while loop: # For-loop for (<Initialization>; <Condition>; <Repeat>) { # Code } # While-Loop <Initialization> while ( <Condition> ) { # Code <Repeat> } Example: Loop 10 times $i = 0 while ($i -lt 10) { Write-Output "Loop value = $i" $i++ } ℹ️ We can get the same behavior with a one liner for loop also: ...

October 7, 2024
PowerShell cover

PowerShell: How to use Where-Object

Where-Object is a cmdlet used for filtering objects in the pipe. Where-Object is placed in between commands and can remove objects that do not meet the criteria. Where-Object takes an object from the pipeline and filters all objects that do not meet the filter_expression. # General data flow: Cmdlet | Where-Object { filter_expression } | Cmdlet Where-Object returns the objects that match the specified condition. The filter includes (filter-in) the desired objects into the output. ...

October 4, 2024
PowerShell cover

PowerShell: How to Change Directory using Set-Location

PowerShell offers a few different ways to change the directory. The official cmdlet to change the directory is Set-Location and it has an aliases: cd, sl, and chdir. PowerShell’s Set-Location is more powerful than Command Prompt’s change directory cd. Set-Location can change directories, change to registry, and change to certificates, and change to environment variables. I will refer to the cmdlet as Set-Location but they can be swapped out with any of the aliases mentioned earlier. cd being common one used. ...

September 29, 2024
PowerShell cover

PowerShell: How to Create Multiple Files

When working with PowerShell, creating multiple files at once can be a convenient way to interact with the file system. In Linux bash, you can use the touch command to create multiple files using a single script line. However, when it comes to PowerShell, things get a bit more complicated. While there isn’t a direct equivalent to the touch command in PowerShell, we can still achieve the same result using PowerShell. We’ll explore various methods for creating multiple files in PowerShell, including using foreach, variables, and even leveraging WSL (Windows Subsystem for Linux) to run the touch command directly. ...

September 24, 2024
PowerShell cover

PowerShell: Git Diff Stash Ambiguous Argument Error

PowerShell is a powerful modern shell for Windows. However, it is not without its quirks. As a modern software developer on Windows you use PowerShell on a regular basis. Sometimes CLI applications (I’m looking at you git) interact with PowerShell in quirky ways. I saw this the other day with git in PowerShell. I was trying to git diff my current changes with the ones in my latest stash stash@{0}. However, when I ran the command git diff stash@{0}, I got the following error: ...

September 21, 2024
PowerShell cover

PowerShell: Select-String Only Return Result Matches

Select-String can be an alternative to Linux’s amazing and well known grep tool. However, grep must be downloaded and setup on the Windows system which might not be possible or convient to do so. A great built-in alternative on Windows PowerShell is Select-String which can do regular expression searching similar to grep. Goal is to have Select-String to only return the match text or the found reuslt. Quick Summary Select-String returns Matches and within it has Value which has the exact text match of the regex without any extra text: (cat .\results.txt | Select-String '<a.*?>.*?</a>').Matches.Value Example: curl a webpage, search a pattern Let’s say we curl’d a webpage and we want to extract the <a>...</a> tags. ...

September 15, 2024
PowerShell cover

PowerShell: Get Local IPv4 Address

Let’s get the local IP version 4 address of the system using PowerShell. We want the actual IPv4 address of the local system but not the localhost loopback address or the link-local address on the system. Link-local address is valid only for communications on local link (subnetwork) that our system is connected to. Link-local addresses are usually 169.254.0.0/16 (169.254.0.0 through 169.254.255.255). 1 Localhost is a hostname that refers to the current computer used to access it. The name localhost is reserved for loopback purposes. The IPv4 loopback address is 127.0.0.1. 2 ...

September 14, 2024
PowerShell cover

Find the Visual Studio Developer PowerShell script

Finding the Developer PowerShell launch script can be difficult as the location for it has change across the different Visual Studio versions (e.g., 2019, 2022), editions (e.g., Community, Professional, Enterprise), and installation location. Visual Studio 2022 and newer install the ‘Developer PowerShell for VS 2022’ as a Windows Terminal profile. This is the easiest way to access it. However, if you want to access it from a PowerShell ps1 script it is more complicated. Accessing via script is done typically if you have to run the script on another system where you don’t know which Visual Studio version/edition/location installed. ...

September 12, 2024
PowerShell cover

PowerShell: Invoke WebRequest Locally

In PowerShell, calling Invoke-WebRequest on a local share, such as \\mydirectory\myFile.txt, will result in an error message such as Invoke-WebRequest: The 'file' scheme is not supported.. If the file is on a network share, the best alternative to Invoke-WebRequest is to simply use Copy-Item. So: Invoke-WebRequest \\mydirectory\myFile.txt -OutFile myFile.txt becomes: Copy-Item \\mydirectory\myFile.txt C:\somewherelocally\myFile.txt I’ve seen this error with FTP also: Invoke-WebRequest: The 'ftp' scheme is not supported. Good news is that curl is shipped with Windows 1. So we can use curl for FTP files: ...

September 12, 2024
PowerShell cover

PowerShell: mkdir and New-Item Without Error

When creating and working with directories in PowerShell and Command Prompt, you may encounter errors when trying to create a new directory using the mkdir command. In best practice, we don’t want commands to throw exceptions or set error flags, as they can cause issues further down the script if not handled correctly. The best course of action is to prevent the error from occuring from the first place. In this article, we’ll go over how to prevent the errors. ...

September 12, 2024
PowerShell cover

PowerShell: Determine Version

Determining the PowerShell version is important for scripts as it tells the script the potential features available on the current PowerShell engine. The best way to do this is use the $PsVersionTable variable in the first method. In this example, the PowerShell version is 7.4.5. Method 1: Use $PSVersionTable Variable The most reliable and recommended way to determine the PowerShell version is using the built-in variable $PSVersionTable. $PSVersionTable contains the infromation about the PowerShell engine including the version. In the shell type $PSVersionTable and press enter. Note, if the variable doesn’t exist then the version is 1.0. ...

September 8, 2024
PowerShell cover

PowerShell: Aliases

The other day I was looking something up for PowerShell and realized that cat command for the classic ‘Windows Command Shell’1 is an alias of Get-Content PowerShell cmdlet. I wondered what other aliases PowerShell has. There is an extensive collection of about 138 default aliases in PowerShell mapping to 109 PowerShell cmdlets on Windows. PowerShell was designed to work with other operating systems too, like Linux and MacOs. If you are new to PowerShell, then these aliases are a good place to learn commands that are often used. ...

September 6, 2024
PowerShell cover

PowerShell: Search Directory Names

Quick tip today. I wanted to find all directories with a certain name specifically .vs because I wanted to delete them. Is the .vs directory safe to delete? Yes, becuase its all generated files by VS that can be deleted. There is also db files in there that intellisense keeps, which can clutter your system after a while. To find all files: gci -recurse -Force -filter ".vs" gci alias for GetChild-Item -recurse to search all sub-directories -Force to search hidden and system files (this is useful for .vs directory because it is typically hidden) -filter to filter which directory or file we want To get the full path of each result: ...

August 7, 2023
PowerShell cover

PowerShell: Read and Edit XML

Create XML in PowerShell Before we start if we don’t have a XML file, we can create one: Set-Content .\test.xml '<?xml version="1.0" encoding="utf-8"?><root/>' Set-Content is a powershell cmd-let to write to a file. The first element is the prolog element 1: <?xml version="1.0" encoding="utf-8"?>. The W3C Recommendation describes the prolog as version number, encoding declaration. If we want to load it and write to it, it must have at least a root element, in this example it is <root> but it can be anything such as <catalog>, <company>, <store>, or even <zoo>. ...

August 5, 2023
PowerShell cover

PowerShell: Create Text File

Command Prompt to PowerShell To create a new text file using PowerShell, use New-Item. Classically, done by echo "some text" > into-a-file.txt, but PowerShell New-Item provides more robustness. The equvalent of the echo redirect > to a new file is PowerShell cmdlet New-Item. In this example, output hello into a new text file in the current directory called myFile.txt. echo hello > myFile.txt New-Item ".\myFile.txt" -Value "hello" -Force Note that New-Item does not replace the file if it already exists by default, we can use -Force to emulate the behavior of the echo redirect. If you run the command without -Force it will give error: New-Item: The file 'C:\myFile.txt' already exists. ...

June 1, 2023
PowerShell cover

PowerShell: Create Shortcut

How do you create a shortcut in Windows via scripts? Easy use PowerShell! Below is the script to create a shortcut named “MyShortcut”. One can additionally create shortcuts to URLs too. I commented everything so it is easy to follow. The only parameter you must set is the $Shortcut.TargetPath everything else is optional. The Windows Script Host (WSH) is a Windows administration tool. Within the Windows Script Host object model the root is Wscript and a sub-node which is WshShell (Wscript.Shell). WshShell object can run programs locally, modify the registry, create shortcuts, or access system folder. Specifically we’re interesting in creating shortcuts. We will access the WSH via the PowerShell script by utilizing the Windows Script Host (WScript) object (via COM) to create the shortcut. ...

May 23, 2023
PowerShell cover

PowerShell: Stop-Process to End Process in Windows

Fastest way to close a running executable in PowerShell is with Stop-Process (alias: kill). Stop-Process is a great tool for developers, especially when developing an application that sometimes doesn’t close properly, has stopped responding, are not shown on screen, or run multiple processes. Stop-Process PowerShell PowerShell 5 and newer can stop processes with Stop-Process (or alias kill) using the process name: Stop-Process -Force -Name 'ProcessName' For example, to close all instances of notepad.exe: ...

April 21, 2021