- Notifications
You must be signed in to change notification settings - Fork396
Download ScriptAnalyzer from PowerShellGallery
License
PowerShell/PSScriptAnalyzer
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Introduction
- Documentation Notice
- Installation
- Contributions are welcome
- Creating a Release
- Code of Conduct
- Security Policy
PSScriptAnalyzer is a static code checker for PowerShell modules and scripts. PSScriptAnalyzerchecks the quality of PowerShell code by running aset of rules. The rules are basedon PowerShell best practices identified by PowerShell Team and the community. It generatesDiagnosticResults (errors and warnings) to inform users about potential code defects and suggestspossible solutions for improvements.
PSScriptAnalyzer ships with a collection of built-in rules that check various aspects ofPowerShell code such as:
- The presence of uninitialized variables
- Use ofPSCredential type
- Use of
Invoke-Expression
- And many more
Conceptual user documentation has been moved out of the source code repository and into thedocumentation repository so that it can be published on learn.microsoft.com.
The goal of this migration is to have the user documentation on learn.microsoft.com. The source coderepository should only contain documentation for the code base, such as how to build the code or howto contribute to the code.
User documentation that has been migrated:
- Most of the contents of this README can be found in thePSScriptAnalyzer overview
- For cmdlet reference, seePSScriptAnalyzer
- For rules, seeRules overview
- The
PowerShellBestPractices.md
content has been moved toPSScriptAnalyzer rules and recommendations - The
ScriptRuleDocumentation.md
content has been moved toCreating custom rules
There is one exception - the documentation for the rules and cmdlets will remain in thedocsfolder to facilitate build testing and to be archived as part of each release. Only thedocumentation for the latest release is published on on learn.microsoft.com.
To installPSScriptAnalyzer from the PowerShell Gallery, seeInstalling PSScriptAnalyzer.
To installPSScriptAnalyzer from source code:
- Latest .NET 8.0 SDK
- If building for Windows PowerShell versions, then the .NET Framework 4.6.2targeting pack (also referred to as developer/targeting pack) need to be installed. This is only possible on Windows.
- Optional but recommended for development:Visual Studio 2022
- OrVisual Studio Code
- Pester v5 PowerShell module, available on PowerShell Gallery
- PlatyPS PowerShell module, available on PowerShell Gallery
Obtain the source
Download the latest source code from therelease page OR
Clone the repository (needs git)
git clone https://github.com/PowerShell/PSScriptAnalyzer
Navigate to the source directory
cd path/to/PSScriptAnalyzer
Building You can either build using the
Visual Studio
solutionPSScriptAnalyzer.sln
or buildusingPowerShell
specifically for your platform as follows:The default build is for the currently used version of PowerShell
.\build.ps1
Windows PowerShell version 5.0
.\build.ps1-PSVersion5
PowerShell 7
.\build.ps1-PSVersion7
Rebuild documentation since it gets built automatically only the first time
.\build.ps1-Documentation
Build all versions (PowerShell v5 and v7) and documentation
.\build.ps1-All
Import the module
Import-Module .\out\PSScriptAnalyzer\[version]\PSScriptAnalyzer.psd1
To confirm installation: runGet-ScriptAnalyzerRule
in the PowerShell console to obtain thebuilt-in rules.
Adding/Removing resource strings
For adding/removing resource strings in the
*.resx
files, it is recommended to useVisual Studio
since it automatically updates the strongly typed*.Designer.cs
files. TheVisual Studio 2017 Community Edition
is free to use but should you not have/want to useVisual Studio
then you can either manually adapt the*.Designer.cs
files or use theNew-StronglyTypedCsFileForResx.ps1
script although the latter is discouraged since it leads to abad diff of the*.Designer.cs
files.
Pester-based ScriptAnalyzer Tests are located inpath/to/PSScriptAnalyzer/Tests
folder.
- EnsurePester of at least version 5.3 is installed
- In the root folder of your local repository, run:
./build-Test
To retrieve the results of the run, you can use the tools which are part of the build module (build.psm1
)
Import-Module ./build.psm1Get-TestResults
To retrieve only the errors, you can use the following:
Import-Module ./build.psm1Get-TestFailures
The documentation in this section can be found inUsing PSScriptAnalyzer.
There are many ways to contribute:
- Open a new bug report, feature request or just ask a question by opening anew issue.
- Participate in the discussions ofissues,pull requests and test fixes or newfeatures.
- Submit your own fixes or features as a pull request but please discuss it beforehand in an issue.
- Submit test cases.
- Update changelog (
changelog.md
) with the new version number and change set. When updating thechangelog please follow the same pattern as that of previous change sets (otherwise this may breakthe next step). - Import the ReleaseMaker module and execute
New-Release
cmdlet to perform the following actions.- Update module manifest (engine/PSScriptAnalyzer.psd1) with the new version number and change set
- Update the version number in
Engine/Engine.csproj
andRules/Rules.csproj
- Create a release build in
out/
Import-Module .\Utils\ReleaseMaker.psm1New-Release
- Sign the binaries and PowerShell files in the release build and publish the module toPowerShell Gallery.
- Draft a new release on github and tag
master
with the new version number.
Please see ourCode of Conduct before participating in this project.
For any security issues, please see ourSecurity Policy.
About
Download ScriptAnalyzer from PowerShellGallery
Topics
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.