How to Check if a String Starts with a Number in PowerShell

Check if a string starts with a number in PowerShell

To check if a string starts with a number in PowerShell, use -match with the pattern ^\d. The caret anchors the match to the start, and \d is any digit: For strict 0 to 9 only, use ^[0-9] instead, because \d accepts digits from other alphabets too. I tested every example in PowerShell 7 and … Read more

How to Get HP BIOS Settings Using PowerShell

Get HP BIOS settings using PowerShell

Rebooting into F10 setup to check one BIOS option gets old fast. HP business PCs expose those options to Windows, so we can read them from a PowerShell window instead. Quick answer: to get HP BIOS settings using PowerShell, run Get-CimInstance against the HP_BIOSEnumeration class in the root\HP\InstrumentedBIOS namespace from an elevated session. Each setting … Read more

Access to the Path Is Denied in PowerShell: Causes and Fixes

Fix access to the path is denied in PowerShell

“Access to the path is denied” in PowerShell means Windows refused the file operation, usually because of a read-only file, a lock held by another program, an NTFS deny rule or a folder path used as a file. For read-only files, -Force fixes it: The trick is figuring out which cause you’ve hit, because each … Read more

How to Find Unquoted Service Paths with PowerShell (and Fix Them)

Find unquoted service paths with PowerShell

To find an unquoted service path with PowerShell, read every service’s PathName from Win32_Service and flag the ones that don’t start with a quote but have a space inside the .exe part: It’s a defensive audit for machines you manage. Below I run it for real in PowerShell 7 and 5.1, test the regex on … Read more

Convert Canonical Name to Distinguished Name in PowerShell

Convert a canonical name to a distinguished name in PowerShell

To convert a canonical name to a distinguished name in PowerShell, split the path on slashes, turn the domain into DC= parts, and add the folders in reverse order. One line handles a simple path: Real paths need more care. Below is a reusable function that handles any depth, the built-in Users container and commas … Read more

PowerShell Out-GridView: PassThru, OutputMode, Wait and Filters

PowerShell Out-GridView interactive grid window

PowerShell Out-GridView sends command output to an interactive table in its own window, where you can sort, filter and pick rows instead of scrolling the console. Pipe any command to it: Add -PassThru and the rows you select come back into the pipeline, which turns the grid into a quick picker for scripts. I ran … Read more

PowerShell Write-Host Color: All 16 Colors and Examples

PowerShell Write-Host color examples with ForegroundColor, BackgroundColor and PSStyle

To change the Write-Host color in PowerShell, add -ForegroundColor for the text and -BackgroundColor for the area behind it: Both parameters take one of 16 console color names. Below I cover the full list, several colors on one line, a reusable status function, and the ANSI colors that only PowerShell 7 understands. Write-Host -ForegroundColor and … Read more

How to Show Progress When Copying Files with PowerShell

Show a progress bar when copying files with PowerShell Write-Progress and Robocopy

To show progress when copying files with PowerShell, loop over the files and call Write-Progress before each Copy-Item. The bar’s percentage is the file number divided by the file count: PowerShell 7.4 and later also give Copy-Item a progress bar of its own. Windows PowerShell 5.1 doesn’t have one, so I’ll show both routes, plus … Read more