Skip to content

Calvindd2f/pslint

Repository files navigation

Contributors Forks Stargazers Issues MIT License LinkedIn


Logo

PSlint

Performance focused linter for PowerShell scripts and modules
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

Product Name Screen Shot

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

(back to top)

Getting Started

Prerequisites

No prerequisites required for using this module

Installation

  1. Install/Import the module

    Install-Module pslint ; Import-Module pslint
  2. Call pslint to the target file or scriptblock

    pslint -Path 'C:\win10_portscan.ps1'
  3. 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.

(back to top)

Usage

For more examples, please refer to the Documentation

(back to top)

Roadmap

  • 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).

(back to top)

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Top contributors

contrib.rocks image

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Your Name - @Dreadytofat - [email protected]

Project Link: https://github.com/calvindd2f/pslint

(back to top)

Acknowledgments

(back to top)

Built With

PowerShell 7

(back to top)