PS C:\> Get-Standard
Models write PowerShell that runs. Not PowerShell you would ship.
The PowerShell Engineer Standard is one document that fixes that, and a set of tools that carry it into whatever you already use.
Prompt Disable AD accounts that have not signed in for 90 days.
# Disables old accounts.
# Pass the number of days.
function Disable-StaleAccounts {
param($Days)
$results = @()
$cutoff = (Get-Date).AddDays(-$Days)
$users = Get-ADUser -Filter * -Properties LastLogonDate
foreach ($u in $users) {
if ($u.LastLogonDate -lt $cutoff) {
Disable-ADAccount -Identity $u
Write-Host "Disabled: $($u.Name)"
$results += $u.Name
}
}
return $results
}
14
issues against the Standard
function Disable-PSEStaleAccount {
<# .SYNOPSIS Disables inactive AD accounts.
.EXAMPLE Get-ADUser -Filter 'Enabled -eq $true' |
Disable-PSEStaleAccount -InactiveDays 90 -WhatIf #>
[CmdletBinding(SupportsShouldProcess, ConfirmImpact='High')]
[OutputType('PSEngineer.AccountResult')]
param(
[Parameter(Mandatory, ValueFromPipeline)]
[ValidateRange(1,3650)][int]$InactiveDays = 90 )
process {
$stale = $_.LastLogonDate -lt $cutoff
if ($stale -and $PSCmdlet.ShouldProcess($_.Name)) {
Disable-ADAccount -Identity $_ -ErrorAction Stop }
[pscustomobject]@{ PSTypeName='PSEngineer.AccountResult'
Name=$_.Name; Action=if($stale){'Disabled'}else{'Skipped'} }
} }
14
issues against the Standard
PSScriptAnalyzer's default rules catch two of these. The Standard catches all fourteen.
What the Standard covers
- Advanced functions, approved verbs, and
[OutputType()]by default - Objects out, never formatted strings
SupportsShouldProcesson anything that changes state- Pipeline support that actually works
- Errors you can catch, with the right terminating behavior
- Help with three examples that run unmodified
- Secrets that never reach a log, a stream, or a process argument
- Comments and READMEs that do not read like they were generated
The tools
Each one is a way to deliver the Standard. The status is honest.
One command, and your repo has a standard
Install-Module PowerShellEngineer -Scope CurrentUser
Add-PSEStandard -Path .
Writes AGENTS.md, Cursor rules, Copilot instructions, an analyzer settings
file, and a GitHub Action. Copilot, Cursor, and Claude Code read them without any
extension installed.