Performance focused linter for PowerShell scripts and modules
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
This is a module for linting performance of PowerShell modules and scripts. This is performance focused so idiomatic PowerShell is not adhered to. Please consider this when weighing maintainability versus performance needs. This module has use cases when a module is encountering resource exhaustion or if you are trying to reduce the time take for Azure Runbooks. The use-cases are non-exhaustive.
The C# version is currently work in progress. The system.management.automation
package is not playing nice. The current PoC that compiles (without all features, so not feasible) is available under the gist
No prerequisites required for using this module
-
Install/Import the module
Install-Module pslint ; Import-Module pslint
-
Call pslint to the target file or scriptblock
pslint -Path 'C:\win10_portscan.ps1'
-
Output
=== PowerShell Performance Analysis Report === Script: C:\Users\c\win10_portscan.ps1 Time: 2024-10-08 03:32:45 Summary: Total Issues Found: 19 == ArrayAddition (2 issues) == Line 81: Code: $IPList.Add($CurrIP) Suggestion: Consider using ArrayList or Generic List for better performance Line 135: Code: $hosts += [PSCustomObject]@{ value = "$($($IP.IP).Trim())"; port = "$($Port.Trim())"; } Suggestion: Consider using ArrayList or Generic List for better performance == LargeCollectionLookup (1 issues) == Line 135: Code: @{ value = "$($($IP.IP).Trim())"; port = "$($Port.Trim())"; } Suggestion: Consider using Dictionary<TKey,TValue> for large collections == OutputSuppression (10 issues) == Line 8: Code: $null|out-null Suggestion: Consider using [void] for better performance Line 9: Code: $null|out-null Suggestion: Consider using [void] for better performance == WriteHostUsage (6 issues) == Line 97: Code: Write-Host "WARNING: Scan took longer than 15 seconds, ARP entries may have been flushed. Recommend lowering DelayMS parameter" Suggestion: Consider using [Console]::writeline() , Write-Output or Write-Information. Line 119: Code: Write-host "Started scanning at $($start_time)" Suggestion: Consider using [Console]::writeline() , Write-Output or Write-Information. Line 172: Code: Write-Host "Hosts Found: $($hosts.Count)" Suggestion: Consider using [Console]::writeline() , Write-Output or Write-Information. Line 175: Code: write-host $(ConvertTo-Json $hosts -Depth 5) Suggestion: Consider using [Console]::writeline() , Write-Output or Write-Information. Line 183: Code: Write-Host "Total Time: $($total.ToString())" Suggestion: Consider using [Console]::writeline() , Write-Output or Write-Information. Line 184: Code: Write-Host "Finished scanning at $($end_time)" Suggestion: Consider using [Console]::writeline() , Write-Output or Write-Information.
For more examples, please refer to the Documentation
- Reliable detection
- Beautified Output Formatting
- Accurate detection (via extensive testing.)
- Pushing module to PSGallery
- Conversion to a CI/CD workflow and a dockerfile for the aforemention workflow.
- Corective action implementation
- Testing
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Your Name - @Dreadytofat - calvin@app-support.com
Project Link: /~https://github.com/calvindd2f/pslint