Do And Do Not - FH-Inway/d365fo.tools GitHub Wiki
Writing Documentation:
Writing Code:
-
Prefer dot notation over
Select -ExpandProperty
.- eg.
(Get-ChildItem).FullName
- eg.
-
When supressing output using null types, use chained assignment.
- eg.
$null = $result = Command-WhichProducedOutputWhenAssigned
- eg.
-
Avoid Write-Output, instead return useful objects closest to the value type of the target
-
If you need to initialize a value, use $null and avoid values such as a blank string
-
-
eg. Constructing a pscustomobject from a hash table, also useful for cheap object creation:
[pscustomobject]@{ ServerName = $servername IsEnabled = $true }
-
-
Avoid continuation marks (backticks) in code if at all possible.
-
Casing follows PowerShell community recommendations:
-
Lower:
- Language keyword (try, catch, foreach)
- Process block keyword (begin, process, end)
-
Pascal:
- Comment help keywords (.Example, .Synopsis)
- Package or modules
- Class
- Exception
- Global variables
-
Camel Case:
- Local variables ($localArgument)
-
There may be rare cases in which features do not work without required casing, in those cases ignore these recommendations.
-
-
The defacto naming convention for any command is ApprovedVerb-D365*
-
Open braces on the same line, Closing braces always on their own line.
Note: This entire page is deeply inspired by the work done over in the dbatool.io module. Pay them a visit and learn from the very same people as we did.