Skip to content
Franck SALLET edited this page Sep 5, 2026 · 1 revision

Utils

Standalone utilities with no ComputerName/Timestamp shape: password generation, string/encoding conversions, Markdown conversion, diacritic removal.

4 function(s) in Public/utils/.

Functions

Reference

ConvertFrom-MisencodedString

Converts a misencoded string by reinterpreting bytes from a source encoding.

Fixes encoding issues where text was incorrectly interpreted using the wrong character encoding. The function takes the string, converts it to bytes using the source encoding (default: Cyrillic), then reinterprets those bytes as ASCII or another target encoding.

This is commonly needed when text was stored or transmitted using one encoding but displayed or processed as another, resulting in garbled characters.

Note: PowerShell converts null input to an empty string before parameter validation runs, so passing -String $null is equivalent to -String ''.

Syntax

ConvertFrom-MisencodedString -String <string> [-SourceEncoding <string>] [-TargetEncoding <string>]

Examples

ConvertFrom-MisencodedString -String 'portal'

Converts a Cyrillic-misencoded string back to readable ASCII text. Returns the corrected string.

'portal', 'server' | ConvertFrom-MisencodedString

Pipeline example: processes multiple misencoded strings and returns the corrected versions.

ConvertFrom-MisencodedString -String 'café' -SourceEncoding 'windows-1252' -TargetEncoding 'utf-8'

Attempts to fix a string where UTF-8 bytes were misinterpreted as Windows-1252. Note: encoding conversion is lossy when characters have no exact mapping in the target encoding. Characters outside the target range are replaced by fallback characters (e.g. '?' for ASCII). Verify results for non-ASCII input.

Get-Content -Path 'C:\Logs\misencoded.txt' | ConvertFrom-MisencodedString

Reads misencoded lines from a file and converts each line to the correct encoding.


ConvertTo-Markdown

Converts PowerShell objects into a GitHub-Flavored Markdown table.

Converts pipeline input or explicitly supplied objects into one complete GitHub-Flavored Markdown table. Column and row order are deterministic: explicit properties retain the requested order, while automatic columns follow first-seen property order and append properties found later.

Pipe characters are escaped, line breaks become
, arrays are joined with comma-space separators, and optional Markdown decorations can be emitted before or after the table.

Syntax

ConvertTo-Markdown [-InputObject <PSObject[]>] [-Property <string[]>] [-Title <string>] [-PreContent <string[]>] [-PostContent <string[]>]

Examples

Get-ScheduledTaskFailure | ConvertTo-Markdown
Converts scheduled task failure objects into a Markdown table.
Get-Service | ConvertTo-Markdown -Property Status, Name, DisplayName
Renders the selected properties in the exact order supplied.
'SRV01', 'SRV02' | ConvertTo-Markdown -Title 'Targets'
Converts pipeline string values into a Markdown table with a Value column.

New-RandomPassword

Generate a cryptographically secure random password.

Generates a random password using RandomNumberGenerator with configurable character class requirements. Ensures minimum counts for uppercase, lowercase, numeric, and special characters are met by guaranteeing placement of required characters followed by cryptographically secure shuffling.

Syntax

New-RandomPassword [-Length <int>] [-UpperCount <int>] [-LowerCount <int>] [-NumericCount <int>] [-SpecialCount <int>]

Examples

New-RandomPassword
Generates a 16-character password with default constraints (2 upper, 2 lower, 2 numeric, 2 special).
New-RandomPassword -Length 24 -UpperCount 4 -LowerCount 4 -NumericCount 4 -SpecialCount 4
Generates a 24-character password with higher complexity requirements.
1..5 | ForEach-Object { New-RandomPassword -Length 20 }
Generates 5 unique passwords with 20 characters each.

Remove-StringDiacritic

Remove diacritical marks from a string using Unicode NFD normalization.

Normalizes the input string to Unicode NFD (Decomposed) form, strips all Non-Spacing Mark characters (accents, cedillas, umlauts, tildes, etc.), then recomposes the result to NFC form. The function is pure .NET and runs on any platform; no Windows dependency or elevation is required.

Syntax

Remove-StringDiacritic -String <string>

Examples

Remove-StringDiacritic -String 'Héllo Wörld'
Returns 'Hello World' — strips the acute accent and umlaut.
'François' | Remove-StringDiacritic
Pipeline with a single string; returns 'Francois'.
'Ångström', 'naïve', 'señor', 'Ünîcödé' | Remove-StringDiacritic
Pipeline with multiple strings; returns each string with diacritics removed.

PSWinOps Wiki

Home

Domains

Clone this wiki locally