Skip to content

no-cmdlet-aliases

Reports a command written with one of the default aliases of Windows PowerShell and PowerShell 7 (gci, ls, %, ?, iex and so on). The table is the one of a Windows host.

Aliases are for typing at a prompt. In a script they are less readable (% and ? are not words), may be absent or mean another command on a platform (ls is the native command on Linux), and users can redefine them.

To fix, write the full name of the cmdlet.

Reported
gci -Recurse | % { $_ }
Get-ChildItem | ? Name -eq x
ls
1..3 | %{ $_ }
Get-ChildItem | Where-Object { $_ } | foreach { $_ }
$x = dir
Write-Output ls
& ls -la
& Get-ChildItem
powershell:
lint:
rules:
no-cmdlet-aliases: warn # off (default), warn, error

Enabled by the presets: powershell/psscriptanalyzer.

Suppress one line with sudsy-disable-next-line no-cmdlet-aliases in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
psscriptanalyzer PSAvoidUsingCmdletAliases partial The table is fixed (a Windows host’s); PSScriptAnalyzer reads the aliases of the host it runs on, so on Linux ls and cat are not aliases there, and user-defined aliases are not known. No fix that expands the alias. & ls is reported at the &.