Explain PowerShell code

Paste a PowerShell script and Vibe explains what each cmdlet in the pipeline passes along, what $_ holds and what -WhatIf would change before anything runs.

Clear-OldLogs.ps1

Up to 1,500 characters (about 60 lines). Your code is sent to Unvibe and Anthropic to write the explanation. Don't paste keys or passwords. Common key formats are refused.

Vibe23 lines selected

Press Explain it for the sample, or paste your own code first.

What this PowerShell sample shows

cmdlets and the pipeline
Get-ChildItem lists the files, | hands each one to Where-Object, which keeps the ones that pass its test, and Sort-Object Length -Descending puts the biggest first. -Filter *.log and -File narrow the list before anything reaches the pipeline, so notes.txt and the folders never show up.
objects and properties
The pipeline passes file objects, not lines of text. Inside { ... }, $_ is the current file, so $_.LastWriteTime and $_.Length are its date and size, with no text to cut apart. @{ Name = "SizeKB"; Expression = { ... } } adds a column worked out for each file, and 1KB is PowerShell's own constant for 1,024.
parameters
param() declares what the script takes. [Parameter(Mandatory)] made a run with no -Path stop with missing mandatory parameters: Path, [int] made -Days abc stop with Cannot convert value "abc" to type "System.Int32", and = 30 is the default when -Days is left out.
WhatIf and ShouldProcess
[CmdletBinding(SupportsShouldProcess)] gives the script a -WhatIf switch. $PSCmdlet.ShouldProcess(...) returns false under -WhatIf and prints the change instead, so the run printed What if: Performing the operation "Delete" on target ... for each old log and deleted nothing.

Good to know

  • Run with PowerShell 7.6.9 on four test files, two .log files from 20 September, one from 4 November and a .txt, with -Days 30 -WhatIf on 5 November: it listed the two September logs, printed 2 files, 250.0 KB and left all four files in place.
  • The same run without -WhatIf, on a copy of the folder, deleted exactly those two logs and kept notes.txt and the November log.
  • With one old file the summary read 1 files, 2.0 KB, and with none 0 files, 0.0 KB. .Count works on a single result and on an empty one in PowerShell 7, so the line never breaks.

Watch out: Use -LiteralPath for file names you didn't type. In a file called app[1].log, -Path reads [1] as a wildcard: Remove-Item -Path matched nothing, deleted nothing and still reported success, while -LiteralPath removed the file.

Explain PowerShell code beside your editor

Unvibe is a free app for Mac and Windows. In the app there is no pasting: select code in any app and press Control+U (Ctrl+Alt+U on Windows).

Install on Mac

curl -fsSL https://unvibe.site/install.sh | bash

Paste into Terminal. Unvibe isn't notarized by Apple yet, so this is the smooth path.

Opening the .dmg the first time
  1. Open the .dmg and drag Unvibe to Applications.
  2. Open it once; macOS says it can't verify it. Click Done.
    macOS dialog: Unvibe Not Opened, with Done and Move to Trash
    Real screen, macOS 15
  3. System Settings › Privacy & Security › Open Anyway. Confirm, then enter your Mac password. The button shows for about an hour after you try to open Unvibe.
    macOS Privacy & Security, Security section: Unvibe was blocked to protect your Mac, with the Open Anyway button
    Real screen, macOS 15

The Terminal line checks the download against the published SHA-256 and Unvibe's self-signed signature before it installs anything. More help with the first open