Category Archives: Best Practices

Powershell Best Practice #6: Use singular noun for cmdlet (not plural noun)

Best Practice: It is recommended to use an English singular noun for cmdlet, do not use plural noun. Explanation: PowerShell cmdlets use the syntax Verb-Noun. Example: Get–Service (“Get” is the verb, “Service” is the noun). Following this syntax convention makes more intuitive what the scope of the cmdlet. (ex: with Get-Service, we know that the cmdlet… Read More »

Powershell Best Practice #4: Use CIM cmdlet (not WMI cmdlet)

Best Practice: It is recommended to use CIM cmdlets, not WMI cmdlets. Explanation: WMI cmdlets are considered obsolete but if you stil use legacy PowerShell v1/2 you could use them. Since Powershell v3 CIM new cmdlets are available.

Microsoft is not spending time on WMI cmdlets, it means that no additional development or improvement… Read More »

Powershell Best Practice #3: Avoid Write-Host

Best Practice: It is recommended to avoid Write-Host (unless your goal is to write to the host only).

Explanation: Write-Host is like a picture sent to the screen, it sends to the host and does not return any objects, it is not possible to export or convert in a specific format. Write-Host has too many limitations.… Read More »

Powershell Best Practice #2: Use named parameter in scripts (not positional and partial parameter)

Best Practice: It is recommended to use named parameter in your scripts and avoid positional and partial (=truncated, shortened, abbreviated) parameter names in your scripts. Explanation: Note: The same logic also could be applied to attribute parameters (line 5)

=== Additional Information When using positional parameters, the syntax can be more difficult to read especially with there… Read More »