@mytechtoday/augment-extensions 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +614 -39
- package/augment-extensions/coding-standards/bash/README.md +196 -0
- package/augment-extensions/coding-standards/bash/module.json +163 -0
- package/augment-extensions/coding-standards/bash/rules/naming-conventions.md +336 -0
- package/augment-extensions/coding-standards/bash/rules/universal-standards.md +289 -0
- package/augment-extensions/coding-standards/css/README.md +40 -0
- package/augment-extensions/coding-standards/css/examples/css-examples.css +550 -0
- package/augment-extensions/coding-standards/css/module.json +44 -0
- package/augment-extensions/coding-standards/css/rules/css-modern-features.md +448 -0
- package/augment-extensions/coding-standards/css/rules/css-standards.md +492 -0
- package/augment-extensions/coding-standards/html/README.md +40 -0
- package/augment-extensions/coding-standards/html/examples/html-examples.html +267 -0
- package/augment-extensions/coding-standards/html/examples/responsive-layout.html +505 -0
- package/augment-extensions/coding-standards/html/module.json +44 -0
- package/augment-extensions/coding-standards/html/rules/html-standards.md +349 -0
- package/augment-extensions/coding-standards/html-css-js/README.md +194 -0
- package/augment-extensions/coding-standards/html-css-js/examples/async-examples.js +487 -0
- package/augment-extensions/coding-standards/html-css-js/examples/css-examples.css +550 -0
- package/augment-extensions/coding-standards/html-css-js/examples/dom-examples.js +667 -0
- package/augment-extensions/coding-standards/html-css-js/examples/html-examples.html +267 -0
- package/augment-extensions/coding-standards/html-css-js/examples/javascript-examples.js +612 -0
- package/augment-extensions/coding-standards/html-css-js/examples/responsive-layout.html +505 -0
- package/augment-extensions/coding-standards/html-css-js/module.json +48 -0
- package/augment-extensions/coding-standards/html-css-js/rules/async-patterns.md +515 -0
- package/augment-extensions/coding-standards/html-css-js/rules/css-modern-features.md +448 -0
- package/augment-extensions/coding-standards/html-css-js/rules/css-standards.md +492 -0
- package/augment-extensions/coding-standards/html-css-js/rules/dom-manipulation.md +439 -0
- package/augment-extensions/coding-standards/html-css-js/rules/html-standards.md +349 -0
- package/augment-extensions/coding-standards/html-css-js/rules/javascript-standards.md +486 -0
- package/augment-extensions/coding-standards/html-css-js/rules/performance.md +463 -0
- package/augment-extensions/coding-standards/html-css-js/rules/tooling.md +543 -0
- package/augment-extensions/coding-standards/js/README.md +46 -0
- package/augment-extensions/coding-standards/js/examples/async-examples.js +487 -0
- package/augment-extensions/coding-standards/js/examples/dom-examples.js +667 -0
- package/augment-extensions/coding-standards/js/examples/javascript-examples.js +612 -0
- package/augment-extensions/coding-standards/js/module.json +49 -0
- package/augment-extensions/coding-standards/js/rules/async-patterns.md +515 -0
- package/augment-extensions/coding-standards/js/rules/dom-manipulation.md +439 -0
- package/augment-extensions/coding-standards/js/rules/javascript-standards.md +486 -0
- package/augment-extensions/coding-standards/js/rules/performance.md +463 -0
- package/augment-extensions/coding-standards/js/rules/tooling.md +543 -0
- package/augment-extensions/coding-standards/php/README.md +248 -0
- package/augment-extensions/coding-standards/php/examples/api-endpoint-example.php +204 -0
- package/augment-extensions/coding-standards/php/examples/cli-command-example.php +206 -0
- package/augment-extensions/coding-standards/php/examples/legacy-refactoring-example.php +234 -0
- package/augment-extensions/coding-standards/php/examples/web-application-example.php +211 -0
- package/augment-extensions/coding-standards/php/examples/woocommerce-extension-example.php +215 -0
- package/augment-extensions/coding-standards/php/examples/wordpress-plugin-example.php +189 -0
- package/augment-extensions/coding-standards/php/module.json +166 -0
- package/augment-extensions/coding-standards/php/rules/api-development.md +480 -0
- package/augment-extensions/coding-standards/php/rules/category-configuration.md +332 -0
- package/augment-extensions/coding-standards/php/rules/cli-tools.md +472 -0
- package/augment-extensions/coding-standards/php/rules/cms-integration.md +561 -0
- package/augment-extensions/coding-standards/php/rules/code-quality.md +402 -0
- package/augment-extensions/coding-standards/php/rules/documentation.md +425 -0
- package/augment-extensions/coding-standards/php/rules/ecommerce.md +627 -0
- package/augment-extensions/coding-standards/php/rules/error-handling.md +336 -0
- package/augment-extensions/coding-standards/php/rules/legacy-migration.md +677 -0
- package/augment-extensions/coding-standards/php/rules/naming-conventions.md +279 -0
- package/augment-extensions/coding-standards/php/rules/performance.md +392 -0
- package/augment-extensions/coding-standards/php/rules/psr-standards.md +186 -0
- package/augment-extensions/coding-standards/php/rules/security.md +358 -0
- package/augment-extensions/coding-standards/php/rules/testing.md +403 -0
- package/augment-extensions/coding-standards/php/rules/type-declarations.md +331 -0
- package/augment-extensions/coding-standards/php/rules/web-applications.md +426 -0
- package/augment-extensions/coding-standards/powershell/README.md +154 -0
- package/augment-extensions/coding-standards/powershell/examples/admin-example.ps1 +272 -0
- package/augment-extensions/coding-standards/powershell/examples/automation-example.ps1 +173 -0
- package/augment-extensions/coding-standards/powershell/examples/cloud-example.ps1 +243 -0
- package/augment-extensions/coding-standards/powershell/examples/cross-platform-example.ps1 +297 -0
- package/augment-extensions/coding-standards/powershell/examples/dsc-example.ps1 +224 -0
- package/augment-extensions/coding-standards/powershell/examples/legacy-migration-example.ps1 +340 -0
- package/augment-extensions/coding-standards/powershell/examples/module-example.psm1 +255 -0
- package/augment-extensions/coding-standards/powershell/module.json +165 -0
- package/augment-extensions/coding-standards/powershell/rules/administrative-tools.md +439 -0
- package/augment-extensions/coding-standards/powershell/rules/automation-scripts.md +240 -0
- package/augment-extensions/coding-standards/powershell/rules/cloud-orchestration.md +384 -0
- package/augment-extensions/coding-standards/powershell/rules/configuration-schema.md +383 -0
- package/augment-extensions/coding-standards/powershell/rules/cross-platform-scripts.md +482 -0
- package/augment-extensions/coding-standards/powershell/rules/dsc-configurations.md +296 -0
- package/augment-extensions/coding-standards/powershell/rules/error-handling.md +314 -0
- package/augment-extensions/coding-standards/powershell/rules/legacy-migrations.md +466 -0
- package/augment-extensions/coding-standards/powershell/rules/modules-functions.md +244 -0
- package/augment-extensions/coding-standards/powershell/rules/naming-conventions.md +266 -0
- package/augment-extensions/coding-standards/powershell/rules/performance-optimization.md +209 -0
- package/augment-extensions/coding-standards/powershell/rules/security-practices.md +314 -0
- package/augment-extensions/coding-standards/powershell/rules/testing-guidelines.md +268 -0
- package/augment-extensions/coding-standards/powershell/rules/universal-standards.md +197 -0
- package/augment-extensions/coding-standards/python/README.md +12 -8
- package/augment-extensions/coding-standards/python/examples/best-practices.py +373 -0
- package/augment-extensions/coding-standards/python/module.json +8 -4
- package/augment-extensions/coding-standards/python/rules/async-patterns.md +884 -0
- package/augment-extensions/coding-standards/python/rules/documentation.md +831 -0
- package/augment-extensions/coding-standards/python/rules/error-handling.md +855 -68
- package/augment-extensions/coding-standards/python/rules/testing.md +409 -0
- package/augment-extensions/coding-standards/python/rules/tooling.md +446 -0
- package/augment-extensions/coding-standards/python/rules/type-hints.md +115 -50
- package/augment-extensions/collections/html-css-js/README.md +82 -0
- package/augment-extensions/collections/html-css-js/collection.json +41 -0
- package/augment-extensions/domain-rules/database/README.md +161 -0
- package/augment-extensions/domain-rules/database/examples/flat-database-example.md +793 -0
- package/augment-extensions/domain-rules/database/examples/hybrid-database-example.md +1132 -0
- package/augment-extensions/domain-rules/database/examples/nosql-document-example.md +868 -0
- package/augment-extensions/domain-rules/database/examples/nosql-graph-example.md +805 -0
- package/augment-extensions/domain-rules/database/examples/relational-schema-example.md +621 -0
- package/augment-extensions/domain-rules/database/examples/vector-database-example.md +965 -0
- package/augment-extensions/domain-rules/database/module.json +28 -0
- package/augment-extensions/domain-rules/database/rules/flat-databases.md +624 -0
- package/augment-extensions/domain-rules/database/rules/nosql-databases.md +588 -0
- package/augment-extensions/domain-rules/database/rules/nosql-document-stores.md +856 -0
- package/augment-extensions/domain-rules/database/rules/nosql-graph-databases.md +778 -0
- package/augment-extensions/domain-rules/database/rules/nosql-key-value-stores.md +963 -0
- package/augment-extensions/domain-rules/database/rules/performance-optimization.md +1076 -0
- package/augment-extensions/domain-rules/database/rules/relational-databases.md +697 -0
- package/augment-extensions/domain-rules/database/rules/relational-indexing.md +671 -0
- package/augment-extensions/domain-rules/database/rules/relational-query-optimization.md +607 -0
- package/augment-extensions/domain-rules/database/rules/relational-schema-design.md +907 -0
- package/augment-extensions/domain-rules/database/rules/relational-transactions.md +783 -0
- package/augment-extensions/domain-rules/database/rules/security-standards.md +980 -0
- package/augment-extensions/domain-rules/database/rules/universal-best-practices.md +485 -0
- package/augment-extensions/domain-rules/database/rules/vector-databases.md +521 -0
- package/augment-extensions/domain-rules/database/rules/vector-embeddings.md +858 -0
- package/augment-extensions/domain-rules/database/rules/vector-indexing.md +934 -0
- package/augment-extensions/domain-rules/mcp/README.md +150 -0
- package/augment-extensions/domain-rules/mcp/examples/compressed-example.md +522 -0
- package/augment-extensions/domain-rules/mcp/examples/graph-augmented-example.md +520 -0
- package/augment-extensions/domain-rules/mcp/examples/hybrid-example.md +570 -0
- package/augment-extensions/domain-rules/mcp/examples/state-based-example.md +427 -0
- package/augment-extensions/domain-rules/mcp/examples/token-based-example.md +435 -0
- package/augment-extensions/domain-rules/mcp/examples/vector-based-example.md +502 -0
- package/augment-extensions/domain-rules/mcp/module.json +49 -0
- package/augment-extensions/domain-rules/mcp/rules/compressed-mcp.md +595 -0
- package/augment-extensions/domain-rules/mcp/rules/configuration.md +345 -0
- package/augment-extensions/domain-rules/mcp/rules/graph-augmented-mcp.md +687 -0
- package/augment-extensions/domain-rules/mcp/rules/hybrid-mcp.md +636 -0
- package/augment-extensions/domain-rules/mcp/rules/state-based-mcp.md +484 -0
- package/augment-extensions/domain-rules/mcp/rules/testing-validation.md +360 -0
- package/augment-extensions/domain-rules/mcp/rules/token-based-mcp.md +393 -0
- package/augment-extensions/domain-rules/mcp/rules/universal-rules.md +194 -0
- package/augment-extensions/domain-rules/mcp/rules/vector-based-mcp.md +625 -0
- package/augment-extensions/workflows/beads/module.json +4 -3
- package/augment-extensions/workflows/database/README.md +195 -0
- package/augment-extensions/workflows/database/ai-prompt-testing.md +295 -0
- package/augment-extensions/workflows/database/examples/migration-example.md +498 -0
- package/augment-extensions/workflows/database/examples/optimization-example.md +496 -0
- package/augment-extensions/workflows/database/examples/schema-design-example.md +444 -0
- package/augment-extensions/workflows/database/module.json +42 -0
- package/augment-extensions/workflows/database/rules/data-migration.md +249 -0
- package/augment-extensions/workflows/database/rules/documentation-standards.md +339 -0
- package/augment-extensions/workflows/database/rules/migration-workflow.md +352 -0
- package/augment-extensions/workflows/database/rules/optimization-workflow.md +435 -0
- package/augment-extensions/workflows/database/rules/schema-design-workflow.md +535 -0
- package/augment-extensions/workflows/database/rules/testing-patterns.md +305 -0
- package/augment-extensions/workflows/database/rules/workflow.md +458 -0
- package/augment-extensions/workflows/openspec/module.json +4 -3
- package/augment-extensions/writing-standards/screenplay/README.md +171 -0
- package/augment-extensions/writing-standards/screenplay/examples/aaa-hollywood-scene.fountain +164 -0
- package/augment-extensions/writing-standards/screenplay/module.json +124 -0
- package/augment-extensions/writing-standards/screenplay/rules/universal-formatting.md +339 -0
- package/cli/MODULES.md +302 -0
- package/cli/dist/cli.js +142 -9
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/catalog.d.ts +13 -0
- package/cli/dist/commands/catalog.d.ts.map +1 -0
- package/cli/dist/commands/catalog.js +104 -0
- package/cli/dist/commands/catalog.js.map +1 -0
- package/cli/dist/commands/gui.d.ts +6 -0
- package/cli/dist/commands/gui.d.ts.map +1 -0
- package/cli/dist/commands/gui.js +211 -0
- package/cli/dist/commands/gui.js.map +1 -0
- package/cli/dist/commands/init.d.ts.map +1 -1
- package/cli/dist/commands/init.js +12 -0
- package/cli/dist/commands/init.js.map +1 -1
- package/cli/dist/commands/install-rules.d.ts +14 -0
- package/cli/dist/commands/install-rules.d.ts.map +1 -0
- package/cli/dist/commands/install-rules.js +127 -0
- package/cli/dist/commands/install-rules.js.map +1 -0
- package/cli/dist/commands/link.d.ts.map +1 -1
- package/cli/dist/commands/link.js +9 -11
- package/cli/dist/commands/link.js.map +1 -1
- package/cli/dist/commands/list.d.ts.map +1 -1
- package/cli/dist/commands/list.js +11 -28
- package/cli/dist/commands/list.js.map +1 -1
- package/cli/dist/commands/mcp.d.ts +48 -0
- package/cli/dist/commands/mcp.d.ts.map +1 -0
- package/cli/dist/commands/mcp.js +229 -0
- package/cli/dist/commands/mcp.js.map +1 -0
- package/cli/dist/commands/self-remove.d.ts +7 -0
- package/cli/dist/commands/self-remove.d.ts.map +1 -0
- package/cli/dist/commands/self-remove.js +179 -0
- package/cli/dist/commands/self-remove.js.map +1 -0
- package/cli/dist/commands/show.d.ts.map +1 -1
- package/cli/dist/commands/show.js +29 -99
- package/cli/dist/commands/show.js.map +1 -1
- package/cli/dist/commands/skill.d.ts +67 -0
- package/cli/dist/commands/skill.d.ts.map +1 -0
- package/cli/dist/commands/skill.js +513 -0
- package/cli/dist/commands/skill.js.map +1 -0
- package/cli/dist/commands/unlink.d.ts +6 -0
- package/cli/dist/commands/unlink.d.ts.map +1 -0
- package/cli/dist/commands/unlink.js +115 -0
- package/cli/dist/commands/unlink.js.map +1 -0
- package/cli/dist/commands/validate.d.ts +6 -0
- package/cli/dist/commands/validate.d.ts.map +1 -0
- package/cli/dist/commands/validate.js +159 -0
- package/cli/dist/commands/validate.js.map +1 -0
- package/cli/dist/utils/catalog-sync.d.ts +22 -0
- package/cli/dist/utils/catalog-sync.d.ts.map +1 -0
- package/cli/dist/utils/catalog-sync.js +157 -0
- package/cli/dist/utils/catalog-sync.js.map +1 -0
- package/cli/dist/utils/character-count.d.ts +56 -0
- package/cli/dist/utils/character-count.d.ts.map +1 -0
- package/cli/dist/utils/character-count.js +190 -0
- package/cli/dist/utils/character-count.js.map +1 -0
- package/cli/dist/utils/documentation-validator.d.ts +18 -0
- package/cli/dist/utils/documentation-validator.d.ts.map +1 -0
- package/cli/dist/utils/documentation-validator.js +233 -0
- package/cli/dist/utils/documentation-validator.js.map +1 -0
- package/cli/dist/utils/install-rules.d.ts +32 -0
- package/cli/dist/utils/install-rules.d.ts.map +1 -0
- package/cli/dist/utils/install-rules.js +375 -0
- package/cli/dist/utils/install-rules.js.map +1 -0
- package/cli/dist/utils/mcp-integration.d.ts +70 -0
- package/cli/dist/utils/mcp-integration.d.ts.map +1 -0
- package/cli/dist/utils/mcp-integration.js +292 -0
- package/cli/dist/utils/mcp-integration.js.map +1 -0
- package/cli/dist/utils/module-system.d.ts +153 -0
- package/cli/dist/utils/module-system.d.ts.map +1 -0
- package/cli/dist/utils/module-system.js +528 -0
- package/cli/dist/utils/module-system.js.map +1 -0
- package/cli/dist/utils/modules-catalog.d.ts +33 -0
- package/cli/dist/utils/modules-catalog.d.ts.map +1 -0
- package/cli/dist/utils/modules-catalog.js +163 -0
- package/cli/dist/utils/modules-catalog.js.map +1 -0
- package/cli/dist/utils/rule-install-hooks.d.ts +19 -0
- package/cli/dist/utils/rule-install-hooks.d.ts.map +1 -0
- package/cli/dist/utils/rule-install-hooks.js +224 -0
- package/cli/dist/utils/rule-install-hooks.js.map +1 -0
- package/cli/dist/utils/skill-system.d.ts +95 -0
- package/cli/dist/utils/skill-system.d.ts.map +1 -0
- package/cli/dist/utils/skill-system.js +313 -0
- package/cli/dist/utils/skill-system.js.map +1 -0
- package/modules.md +518 -106
- package/package.json +12 -3
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# PowerShell Naming Conventions
|
|
2
|
+
|
|
3
|
+
Comprehensive naming standards for PowerShell code following Microsoft best practices.
|
|
4
|
+
|
|
5
|
+
## Function and Cmdlet Names
|
|
6
|
+
|
|
7
|
+
### Verb-Noun Pattern
|
|
8
|
+
|
|
9
|
+
**ALWAYS** use approved verbs with singular nouns:
|
|
10
|
+
|
|
11
|
+
```powershell
|
|
12
|
+
# ✅ Correct
|
|
13
|
+
Get-User
|
|
14
|
+
Set-Configuration
|
|
15
|
+
New-LogEntry
|
|
16
|
+
Remove-TempFile
|
|
17
|
+
|
|
18
|
+
# ❌ Incorrect
|
|
19
|
+
GetUser # Missing hyphen
|
|
20
|
+
Get-Users # Plural noun
|
|
21
|
+
Fetch-User # Unapproved verb
|
|
22
|
+
Get_User # Underscore instead of hyphen
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### Approved Verbs
|
|
26
|
+
|
|
27
|
+
Use `Get-Verb` to see all approved verbs. Common categories:
|
|
28
|
+
|
|
29
|
+
**Common Verbs:**
|
|
30
|
+
- `Get`, `Set`, `New`, `Remove`
|
|
31
|
+
- `Add`, `Clear`, `Copy`, `Move`
|
|
32
|
+
- `Find`, `Search`, `Select`, `Show`
|
|
33
|
+
- `Start`, `Stop`, `Restart`, `Suspend`
|
|
34
|
+
- `Read`, `Write`, `Update`, `Invoke`
|
|
35
|
+
|
|
36
|
+
**Data Verbs:**
|
|
37
|
+
- `Backup`, `Restore`, `Save`, `Sync`
|
|
38
|
+
- `Compare`, `Convert`, `Export`, `Import`
|
|
39
|
+
- `Merge`, `Split`, `Compress`, `Expand`
|
|
40
|
+
|
|
41
|
+
**Lifecycle Verbs:**
|
|
42
|
+
- `Initialize`, `Register`, `Unregister`
|
|
43
|
+
- `Enable`, `Disable`, `Install`, `Uninstall`
|
|
44
|
+
|
|
45
|
+
**Diagnostic Verbs:**
|
|
46
|
+
- `Test`, `Trace`, `Measure`, `Debug`
|
|
47
|
+
- `Confirm`, `Assert`, `Validate`
|
|
48
|
+
|
|
49
|
+
### Verb Selection Guidelines
|
|
50
|
+
|
|
51
|
+
```powershell
|
|
52
|
+
# ✅ Use Get for retrieval
|
|
53
|
+
Get-UserProfile
|
|
54
|
+
|
|
55
|
+
# ✅ Use Set for modification
|
|
56
|
+
Set-UserProfile
|
|
57
|
+
|
|
58
|
+
# ✅ Use New for creation
|
|
59
|
+
New-UserProfile
|
|
60
|
+
|
|
61
|
+
# ✅ Use Remove for deletion
|
|
62
|
+
Remove-UserProfile
|
|
63
|
+
|
|
64
|
+
# ✅ Use Test for validation (returns boolean)
|
|
65
|
+
Test-UserExists
|
|
66
|
+
|
|
67
|
+
# ✅ Use Invoke for execution
|
|
68
|
+
Invoke-UserScript
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Variable Names
|
|
72
|
+
|
|
73
|
+
### PascalCase for Variables
|
|
74
|
+
|
|
75
|
+
```powershell
|
|
76
|
+
# ✅ Correct
|
|
77
|
+
$UserName = "john.doe"
|
|
78
|
+
$FilePath = "C:\Logs\app.log"
|
|
79
|
+
$MaxRetryCount = 3
|
|
80
|
+
$IsEnabled = $true
|
|
81
|
+
|
|
82
|
+
# ❌ Incorrect
|
|
83
|
+
$username # camelCase
|
|
84
|
+
$file_path # snake_case
|
|
85
|
+
$MAXRETRYCOUNT # ALL CAPS (reserved for constants)
|
|
86
|
+
$is-enabled # kebab-case
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Descriptive Names
|
|
90
|
+
|
|
91
|
+
```powershell
|
|
92
|
+
# ✅ Descriptive
|
|
93
|
+
$DatabaseConnectionString
|
|
94
|
+
$UserEmailAddress
|
|
95
|
+
$MaximumRetryAttempts
|
|
96
|
+
|
|
97
|
+
# ❌ Too short/cryptic
|
|
98
|
+
$dcs
|
|
99
|
+
$email
|
|
100
|
+
$max
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Boolean Variables
|
|
104
|
+
|
|
105
|
+
Prefix with `Is`, `Has`, `Should`, `Can`:
|
|
106
|
+
|
|
107
|
+
```powershell
|
|
108
|
+
$IsValid = $true
|
|
109
|
+
$HasPermission = $false
|
|
110
|
+
$ShouldContinue = $true
|
|
111
|
+
$CanWrite = Test-Path $path -PathType Leaf
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Collections
|
|
115
|
+
|
|
116
|
+
Use plural nouns:
|
|
117
|
+
|
|
118
|
+
```powershell
|
|
119
|
+
$Users = @()
|
|
120
|
+
$Files = Get-ChildItem
|
|
121
|
+
$ErrorMessages = @()
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Parameter Names
|
|
125
|
+
|
|
126
|
+
### PascalCase and Descriptive
|
|
127
|
+
|
|
128
|
+
```powershell
|
|
129
|
+
function Get-UserData
|
|
130
|
+
{
|
|
131
|
+
[CmdletBinding()]
|
|
132
|
+
param(
|
|
133
|
+
[Parameter(Mandatory)]
|
|
134
|
+
[string]$UserName,
|
|
135
|
+
|
|
136
|
+
[Parameter()]
|
|
137
|
+
[string]$DomainName = 'contoso.com',
|
|
138
|
+
|
|
139
|
+
[Parameter()]
|
|
140
|
+
[switch]$IncludeGroups
|
|
141
|
+
)
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Common Parameter Names
|
|
146
|
+
|
|
147
|
+
Follow PowerShell conventions:
|
|
148
|
+
|
|
149
|
+
```powershell
|
|
150
|
+
# ✅ Standard names
|
|
151
|
+
-Path # File/folder paths
|
|
152
|
+
-Name # Object names
|
|
153
|
+
-ComputerName # Remote computer
|
|
154
|
+
-Credential # PSCredential object
|
|
155
|
+
-Force # Override confirmations
|
|
156
|
+
-WhatIf # Simulation mode
|
|
157
|
+
-Confirm # Confirmation prompts
|
|
158
|
+
-Verbose # Verbose output
|
|
159
|
+
-Debug # Debug output
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Constants and Enums
|
|
163
|
+
|
|
164
|
+
### ALL_CAPS with Underscores
|
|
165
|
+
|
|
166
|
+
```powershell
|
|
167
|
+
# Constants
|
|
168
|
+
$MAX_RETRY_COUNT = 5
|
|
169
|
+
$DEFAULT_TIMEOUT_SECONDS = 30
|
|
170
|
+
$API_BASE_URL = 'https://api.example.com'
|
|
171
|
+
|
|
172
|
+
# Enums
|
|
173
|
+
enum LogLevel
|
|
174
|
+
{
|
|
175
|
+
DEBUG
|
|
176
|
+
INFO
|
|
177
|
+
WARNING
|
|
178
|
+
ERROR
|
|
179
|
+
CRITICAL
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## File Names
|
|
184
|
+
|
|
185
|
+
### Script Files (.ps1)
|
|
186
|
+
|
|
187
|
+
```powershell
|
|
188
|
+
# ✅ Correct
|
|
189
|
+
Get-UserReport.ps1
|
|
190
|
+
Deploy-Application.ps1
|
|
191
|
+
Backup-Database.ps1
|
|
192
|
+
|
|
193
|
+
# ❌ Incorrect
|
|
194
|
+
getUserReport.ps1 # camelCase
|
|
195
|
+
get_user_report.ps1 # snake_case
|
|
196
|
+
script1.ps1 # Non-descriptive
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Module Files
|
|
200
|
+
|
|
201
|
+
```powershell
|
|
202
|
+
# Module manifest (.psd1)
|
|
203
|
+
MyModule.psd1
|
|
204
|
+
|
|
205
|
+
# Module script (.psm1)
|
|
206
|
+
MyModule.psm1
|
|
207
|
+
|
|
208
|
+
# Module folder
|
|
209
|
+
MyModule/
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Class Names
|
|
213
|
+
|
|
214
|
+
### PascalCase
|
|
215
|
+
|
|
216
|
+
```powershell
|
|
217
|
+
class UserAccount
|
|
218
|
+
{
|
|
219
|
+
[string]$UserName
|
|
220
|
+
[string]$Email
|
|
221
|
+
[datetime]$CreatedDate
|
|
222
|
+
|
|
223
|
+
UserAccount([string]$userName, [string]$email)
|
|
224
|
+
{
|
|
225
|
+
$this.UserName = $userName
|
|
226
|
+
$this.Email = $email
|
|
227
|
+
$this.CreatedDate = Get-Date
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Anti-Patterns
|
|
233
|
+
|
|
234
|
+
### Avoid These
|
|
235
|
+
|
|
236
|
+
```powershell
|
|
237
|
+
# ❌ Hungarian notation
|
|
238
|
+
$strUserName
|
|
239
|
+
$intCount
|
|
240
|
+
$arrUsers
|
|
241
|
+
|
|
242
|
+
# ❌ Abbreviations (unless widely known)
|
|
243
|
+
$usr
|
|
244
|
+
$cnt
|
|
245
|
+
$msg
|
|
246
|
+
|
|
247
|
+
# ❌ Single letters (except loop counters)
|
|
248
|
+
$x
|
|
249
|
+
$y
|
|
250
|
+
$z
|
|
251
|
+
|
|
252
|
+
# ✅ Loop counters are OK
|
|
253
|
+
for ($i = 0; $i -lt 10; $i++)
|
|
254
|
+
{
|
|
255
|
+
# Process
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
## Best Practices
|
|
260
|
+
|
|
261
|
+
1. **Be consistent** - Follow the same pattern throughout your codebase
|
|
262
|
+
2. **Be descriptive** - Names should explain purpose without comments
|
|
263
|
+
3. **Use approved verbs** - Check with `Get-Verb`
|
|
264
|
+
4. **Avoid abbreviations** - Unless universally understood (URL, API, SQL)
|
|
265
|
+
5. **Follow PowerShell conventions** - Match built-in cmdlet patterns
|
|
266
|
+
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# PowerShell Performance Optimization
|
|
2
|
+
|
|
3
|
+
Comprehensive performance optimization techniques for efficient PowerShell code.
|
|
4
|
+
|
|
5
|
+
## Pipeline Efficiency
|
|
6
|
+
|
|
7
|
+
### Use Pipeline Correctly
|
|
8
|
+
|
|
9
|
+
**PREFER** pipeline over loops when possible:
|
|
10
|
+
|
|
11
|
+
```powershell
|
|
12
|
+
# ✅ GOOD: Pipeline (faster)
|
|
13
|
+
Get-ChildItem -Path C:\Logs -Filter *.log | Where-Object { $_.Length -gt 1MB } | Remove-Item
|
|
14
|
+
|
|
15
|
+
# ❌ BAD: ForEach loop (slower)
|
|
16
|
+
$files = Get-ChildItem -Path C:\Logs -Filter *.log
|
|
17
|
+
foreach ($file in $files) {
|
|
18
|
+
if ($file.Length -gt 1MB) {
|
|
19
|
+
Remove-Item $file
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
### Filter Left, Format Right
|
|
25
|
+
|
|
26
|
+
**ALWAYS** filter as early as possible:
|
|
27
|
+
|
|
28
|
+
```powershell
|
|
29
|
+
# ✅ GOOD: Filter at source
|
|
30
|
+
Get-ChildItem -Path C:\Logs -Filter *.log | Where-Object { $_.Length -gt 1MB }
|
|
31
|
+
|
|
32
|
+
# ❌ BAD: Get everything then filter
|
|
33
|
+
Get-ChildItem -Path C:\Logs | Where-Object { $_.Name -like '*.log' -and $_.Length -gt 1MB }
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Avoid Unnecessary Pipeline Operations
|
|
37
|
+
|
|
38
|
+
```powershell
|
|
39
|
+
# ✅ GOOD: Direct assignment
|
|
40
|
+
$processes = Get-Process
|
|
41
|
+
|
|
42
|
+
# ❌ BAD: Unnecessary ForEach-Object
|
|
43
|
+
$processes = Get-Process | ForEach-Object { $_ }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Loop Performance
|
|
47
|
+
|
|
48
|
+
### foreach vs ForEach-Object
|
|
49
|
+
|
|
50
|
+
**USE** `foreach` statement for better performance:
|
|
51
|
+
|
|
52
|
+
```powershell
|
|
53
|
+
# ✅ GOOD: foreach statement (fastest)
|
|
54
|
+
$items = 1..10000
|
|
55
|
+
foreach ($item in $items) {
|
|
56
|
+
$result = $item * 2
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
# ❌ SLOWER: ForEach-Object cmdlet
|
|
60
|
+
$items = 1..10000
|
|
61
|
+
$items | ForEach-Object {
|
|
62
|
+
$result = $_ * 2
|
|
63
|
+
}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**WHEN** to use ForEach-Object:
|
|
67
|
+
- Processing pipeline input
|
|
68
|
+
- Need to stream large datasets
|
|
69
|
+
- Want lazy evaluation
|
|
70
|
+
|
|
71
|
+
### Avoid Nested Loops
|
|
72
|
+
|
|
73
|
+
```powershell
|
|
74
|
+
# ✅ GOOD: Use hashtable for lookups
|
|
75
|
+
$userLookup = @{}
|
|
76
|
+
foreach ($user in $users) {
|
|
77
|
+
$userLookup[$user.Id] = $user
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
foreach ($order in $orders) {
|
|
81
|
+
$user = $userLookup[$order.UserId] # O(1) lookup
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
# ❌ BAD: Nested loops
|
|
85
|
+
foreach ($order in $orders) {
|
|
86
|
+
foreach ($user in $users) { # O(n²) complexity
|
|
87
|
+
if ($user.Id -eq $order.UserId) {
|
|
88
|
+
# Process
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Memory Management
|
|
95
|
+
|
|
96
|
+
### Use [System.Collections.Generic.List] for Dynamic Arrays
|
|
97
|
+
|
|
98
|
+
```powershell
|
|
99
|
+
# ✅ GOOD: Generic List (efficient)
|
|
100
|
+
$list = [System.Collections.Generic.List[string]]::new()
|
|
101
|
+
foreach ($item in 1..10000) {
|
|
102
|
+
$list.Add("Item $item")
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
# ❌ BAD: Array concatenation (slow)
|
|
106
|
+
$array = @()
|
|
107
|
+
foreach ($item in 1..10000) {
|
|
108
|
+
$array += "Item $item" # Creates new array each time
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Dispose of Large Objects
|
|
113
|
+
|
|
114
|
+
```powershell
|
|
115
|
+
# ✅ GOOD: Explicit disposal
|
|
116
|
+
$stream = [System.IO.StreamReader]::new('large-file.txt')
|
|
117
|
+
try {
|
|
118
|
+
$content = $stream.ReadToEnd()
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
$stream.Dispose()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
# ✅ BETTER: Using statement (PowerShell 7+)
|
|
125
|
+
using ($stream = [System.IO.StreamReader]::new('large-file.txt')) {
|
|
126
|
+
$content = $stream.ReadToEnd()
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Clear Variables When Done
|
|
131
|
+
|
|
132
|
+
```powershell
|
|
133
|
+
# Clear large variables
|
|
134
|
+
$largeData = Get-LargeDataset
|
|
135
|
+
# Process data
|
|
136
|
+
$largeData = $null
|
|
137
|
+
[System.GC]::Collect() # Force garbage collection (use sparingly)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## String Operations
|
|
141
|
+
|
|
142
|
+
### Use StringBuilder for Concatenation
|
|
143
|
+
|
|
144
|
+
```powershell
|
|
145
|
+
# ✅ GOOD: StringBuilder
|
|
146
|
+
$sb = [System.Text.StringBuilder]::new()
|
|
147
|
+
foreach ($item in 1..1000) {
|
|
148
|
+
[void]$sb.AppendLine("Line $item")
|
|
149
|
+
}
|
|
150
|
+
$result = $sb.ToString()
|
|
151
|
+
|
|
152
|
+
# ❌ BAD: String concatenation
|
|
153
|
+
$result = ''
|
|
154
|
+
foreach ($item in 1..1000) {
|
|
155
|
+
$result += "Line $item`n" # Creates new string each time
|
|
156
|
+
}
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Use -join for Arrays
|
|
160
|
+
|
|
161
|
+
```powershell
|
|
162
|
+
# ✅ GOOD: -join operator
|
|
163
|
+
$items = 1..1000
|
|
164
|
+
$result = $items -join ', '
|
|
165
|
+
|
|
166
|
+
# ❌ BAD: String concatenation in loop
|
|
167
|
+
$result = ''
|
|
168
|
+
foreach ($item in $items) {
|
|
169
|
+
$result += "$item, "
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Cmdlet-Specific Optimizations
|
|
174
|
+
|
|
175
|
+
### Use -Filter Instead of Where-Object
|
|
176
|
+
|
|
177
|
+
```powershell
|
|
178
|
+
# ✅ GOOD: Server-side filtering
|
|
179
|
+
Get-ChildItem -Path C:\Logs -Filter *.log
|
|
180
|
+
|
|
181
|
+
# ❌ BAD: Client-side filtering
|
|
182
|
+
Get-ChildItem -Path C:\Logs | Where-Object { $_.Extension -eq '.log' }
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Use -ReadCount for Large Files
|
|
186
|
+
|
|
187
|
+
```powershell
|
|
188
|
+
# ✅ GOOD: Process in batches
|
|
189
|
+
Get-Content -Path large-file.txt -ReadCount 1000 | ForEach-Object {
|
|
190
|
+
# Process batch of 1000 lines
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
# ❌ BAD: Load entire file
|
|
194
|
+
$content = Get-Content -Path large-file.txt
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Best Practices Summary
|
|
198
|
+
|
|
199
|
+
1. **Filter early** - Use -Filter parameter when available
|
|
200
|
+
2. **Use foreach statement** - Faster than ForEach-Object for arrays
|
|
201
|
+
3. **Avoid array concatenation** - Use Generic.List for dynamic arrays
|
|
202
|
+
4. **Use StringBuilder** - For string concatenation in loops
|
|
203
|
+
5. **Dispose resources** - Clean up streams, connections, large objects
|
|
204
|
+
6. **Measure performance** - Use Measure-Command to profile
|
|
205
|
+
7. **Avoid nested loops** - Use hashtables for lookups
|
|
206
|
+
8. **Stream large files** - Use -ReadCount or StreamReader
|
|
207
|
+
9. **Cache results** - Don't repeat expensive operations
|
|
208
|
+
10. **Use .NET types** - When PowerShell cmdlets are too slow
|
|
209
|
+
|