I would like to get all PowerShell-Cmdlets in the current session that have no parameters (if they are any).
When I try
Get-Command -CommandType Cmdlet | Where-Object { $_.Parameters.Count -eq 0 } | Select-Object -Property Name, @{n="PCount";e={$_.Parameters.Count}}
I'll get a lot of Cmdlets. But it turns out that they actually have parameters:
(Get-Command -Name Write-Host).Parameters.Count
What is the correct way to get Cmdlets that have no parameters?
You should get no results from your filter however, as you stated you're getting wrong results and this is most likely due to lazy loading of the parameter info of each command, a consecutive piping to
Get-Commandforces the cmdlets' module to be loaded then the issue is gone, usingCimCmdletsModule as example:If you want to get all cmdlets having no parameters but excluding
CommonParametersandOptionalCommonParametersyou could use:Or, tip from Mathias, easier way using the
CommandMetadataclass to get the commands' parameters excluding common and optional: