• Stars
    star
    1,764
  • Rank 25,321 (Top 0.6 %)
  • Language
    C#
  • License
    MIT License
  • Created about 9 years ago
  • Updated 28 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Download ScriptAnalyzer from PowerShellGallery

PSScriptAnalyzer

Build Status Join the chat at https://gitter.im/PowerShell/PSScriptAnalyzer

Table of Contents

Introduction

PSScriptAnalyzer is a static code checker for PowerShell modules and scripts. PSScriptAnalyzer checks the quality of PowerShell code by running a set of rules. The rules are based on PowerShell best practices identified by PowerShell Team and the community. It generates DiagnosticResults (errors and warnings) to inform users about potential code defects and suggests possible solutions for improvements.

PSScriptAnalyzer ships with a collection of built-in rules that check various aspects of PowerShell code such as:

  • The presence of uninitialized variables
  • Use of PSCredential type
  • Use of Invoke-Expression
  • And many more

Back to ToC

DOCUMENTATION NOTICE

Conceptual user documentation has been moved out of the source code repository and into the documentation 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 code repository should only contain documentation for the code base, such as how to build the code or how to contribute to the code.

User documentation that has been migrated:

There is one exception - the documentation for the rules and cmdlets will remain in the docs folder to facilitate build testing and to be archived as part of each release. Only the documentation for the latest release is published on on learn.microsoft.com.

Installation

To install PSScriptAnalyzer from the PowerShell Gallery, see Installing PSScriptAnalyzer.

To install PSScriptAnalyzer from source code:

Requirements

  • If building for Windows PowerShell versions, then the .NET Framework 4.6.2 targeting pack (also referred to as developer/targeting pack) need to be installed. This is only possible on Windows.
  • Optionally but recommended for development: Visual Studio 2017/2019

Steps

  • Obtain the source

    • Download the latest source code from the release 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 solution PSScriptAnalyzer.sln or build using PowerShell 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 -PSVersion 5
    • Windows PowerShell version 4.0

      .\build.ps1 -PSVersion 4
    • Windows PowerShell version 3.0

      .\build.ps1 -PSVersion 3
    • PowerShell 7

      .\build.ps1 -PSVersion 7
  • Rebuild documentation since it gets built automatically only the first time

    .\build.ps1 -Documentation
  • Build all versions (PowerShell v3, v4, v5, and v6) and documentation

    .\build.ps1 -All
  • Import the module

    Import-Module .\out\PSScriptAnalyzer\[version]\PSScriptAnalyzer.psd1

To confirm installation: run Get-ScriptAnalyzerRule in the PowerShell console to obtain the built-in rules.

  • Adding/Removing resource strings

    For adding/removing resource strings in the *.resx files, it is recommended to use Visual Studio since it automatically updates the strongly typed *.Designer.cs files. The Visual Studio 2017 Community Edition is free to use but should you not have/want to use Visual Studio then you can either manually adapt the *.Designer.cs files or use the New-StronglyTypedCsFileForResx.ps1 script although the latter is discouraged since it leads to a bad diff of the *.Designer.cs files.

Tests

Pester-based ScriptAnalyzer Tests are located in path/to/PSScriptAnalyzer/Tests folder.

  • Ensure Pester 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.psm1
Get-TestResults

To retrieve only the errors, you can use the following:

Import-Module ./build.psm1
Get-TestFailures

Back to ToC

Using PSScriptAnalyzer

The documentation in this section can be found in Using PSScriptAnalyzer.

Contributions are welcome

There are many ways to contribute:

  1. Open a new bug report, feature request or just ask a question by opening a new issue.
  2. Participate in the discussions of issues, pull requests and test fixes or new features.
  3. Submit your own fixes or features as a pull request but please discuss it beforehand in an issue.
  4. Submit test cases.

Back to ToC

Creating a Release

  • Update changelog (changelog.md) with the new version number and change set. When updating the changelog please follow the same pattern as that of previous change sets (otherwise this may break the 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 and Rules/Rules.csproj
    • Create a release build in out/
Import-Module .\Utils\ReleaseMaker.psm1
New-Release
  • Sign the binaries and PowerShell files in the release build and publish the module to PowerShell Gallery.
  • Draft a new release on github and tag master with the new version number.

Back to ToC

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Back to ToC

More Repositories

1

PowerShell

PowerShell for every system!
C#
43,120
star
2

Win32-OpenSSH

Win32 port of OpenSSH
7,063
star
3

PSReadLine

A bash inspired readline implementation for PowerShell
C#
3,494
star
4

vscode-powershell

Provides PowerShell language and debugging support for Visual Studio Code
TypeScript
1,647
star
5

DscResources

Central repository for PowerShell Desired State Configuration (DSC) resources.
772
star
6

platyPS

Write PowerShell External Help in Markdown
C#
729
star
7

ConsoleGuiTools

Modules that mix PowerShell and GUIs/CUIs! - built on Avalonia and gui.cs
C#
708
star
8

PowerShellEditorServices

A common platform for PowerShell development support in any editor or application!
C#
593
star
9

Polaris

A cross-platform, minimalist web framework for PowerShell
PowerShell
506
star
10

PSResourceGet

PSResourceGet is the package manager for PowerShell
C#
453
star
11

PowerShellGetv2

PowerShellGet is the Package Manager for PowerShell
PowerShell
426
star
12

PowerShell-RFC

RFC (Request for Comments) documents for community feedback on design changes and improvements to PowerShell ecosystem
PowerShell
418
star
13

Crescendo

a module for wrapping native applications in a PowerShell function and module
PowerShell
378
star
14

PowerShell-Docker

Repository for building PowerShell Docker images
Dockerfile
377
star
15

SecretManagement

PowerShell module to consistent usage of secrets through different extension vaults
C#
302
star
16

JEA

Just Enough Administration
PowerShell
253
star
17

Operation-Validation-Framework

PowerShell
223
star
18

PowerShellGallery

PowerShell
210
star
19

SHiPS

Simple Hierarchy in PowerShell - developing PowerShell provider got so much easier
C#
184
star
20

PSSwagger

The cmdlet generator from OpenAPI (f.k.a Swagger) specification
PowerShell
163
star
21

PowerShellStandard

C#
158
star
22

SecretStore

C#
147
star
23

PSPrivateGallery

DSC Resources and Configurations to deploy and manage Private PowerShell Gallery
PowerShell
147
star
24

WindowsCompatibility

Module that allows Windows PowerShell Modules to be used from PSCore6
PowerShell
135
star
25

PowerShell-IoT

Interact with I2C, SPI & GPIO devices using PowerShell Core!
C#
129
star
26

PowerShell-Tests

Pester based tests for testing PowerShell
PowerShell
128
star
27

GPRegistryPolicyParser

PowerShell
128
star
28

PSDscResources

PowerShell
128
star
29

EditorSyntax

Syntax highlighting files for editors (VSCode, Atom, SublimeText, TextMate, etc) and GitHub!
PowerShell
122
star
30

CompletionPredictor

C#
118
star
31

Modules

C#
112
star
32

Phosphor

A library and PowerShell module for generating user interfaces from PowerShell modules
TypeScript
109
star
33

GPRegistryPolicy

PowerShell
99
star
34

psl-omi-provider

PSRP Linux support library
C
99
star
35

DSC

This repo is for the DSC v3 project
Rust
96
star
36

Microsoft.PowerShell.Archive

Archive PowerShell module contains cmdlets for working with ZIP archives
C#
92
star
37

Community-Blog

Submissions for posts to the PowerShell Community Blog -https://devblogs.microsoft.com/powershell-community
90
star
38

PSArm

PSArm is a PowerShell module that provides a PowerShell-embedded domain-specific language (DSL) for Azure Resource Manager (ARM) templates
C#
77
star
39

Remotely

Enable remote execution of scripts. Works with Pester.
PowerShell
75
star
40

TextUtility

Microsoft.PowerShell.TextUtility module
C#
58
star
41

Demo_CI

PowerShell
56
star
42

DscResource.Tests

Common meta tests for PowerShell DSC resources repositories.
PowerShell
51
star
43

PSDesiredStateConfiguration

Source for https://www.powershellgallery.com/packages/PSDesiredStateConfiguration module
PowerShell
49
star
44

Whitepapers

Staging area for new documents and whitepapers
46
star
45

PowerShell-Native

C++
44
star
46

AzurePSDrive

Navigate Azure Resources Just like A FileSystem
PowerShell
41
star
47

ContainerProvider

ContainerImageProvider
PowerShell
38
star
48

PackageManagementProviderResource

Modules with DSC resources for the PackageManagement(aka OneGet) providers.
PowerShell
37
star
49

PrivateCloud.DiagnosticInfo

PowerShell
37
star
50

Pager

Project for console pager, which is published as a NuGet package Microsoft.PowerShell.Pager
C#
34
star
51

PowerShellGet

This module provide functions used with PowerShellGet v3 to provide compatibility with scripts expecting PowerShellGet v2
PowerShell
33
star
52

PlasterBuild

Provides common build tasks for PowerShell module projects
PowerShell
29
star
53

CimPSDrive

SHiPS based provider to navigate CIM classes and namespaces
PowerShell
27
star
54

DscConfigurations

PowerShell
27
star
55

MarkdownRender

C#
27
star
56

SelfSignedCertificate

A module for generating self-signed certificates in PowerShell Core
PowerShell
25
star
57

GitHub-Actions

PowerShell
25
star
58

MMI

C#
25
star
59

tree-sitter-PowerShell

JavaScript
24
star
60

PowerShell-Snap

PowerShell
24
star
61

Microsoft.PowerShell.Kubectl

PowerShell module to manage Kubernetes
PowerShell
23
star
62

ODataUtils

PowerShell Module to generate cmdlets from an OData endpoint
PowerShell
22
star
63

DSC-Samples

Samples and tutorials for DSC v3
Go
21
star
64

WmiNamespaceSecurityDsc

This module contains DSC resources to manage WMI Namespace Security.
PowerShell
21
star
65

ThreadJob

PowerShell
21
star
66

FileUtility

C#
21
star
67

UnixCompleters

C#
18
star
68

underhanded-powershell

Underhanded PowerShell Contest Repository
PowerShell
18
star
69

LibreSSL

C
17
star
70

Hardware-Management-Module

PowerShell
17
star
71

Homebrew-Tap

Ruby
16
star
72

generator-powershell

Create PowerShell modules and scripts using Yeoman!
JavaScript
16
star
73

JsonAdapter

C#
13
star
74

Announcements

PowerShell Team Announcements
12
star
75

PowerShellModuleCoverage

Track issues related to using Windows PowerShell modules with PowerShell
12
star
76

PSRelease

PowerShell
11
star
77

whatsnew

PowerShell
11
star
78

AwsDscToolkit

AWS DSC Toolkit
PowerShell
10
star
79

DscResource.Template

PowerShell
10
star
80

TemplateConfig

Provides template for organizing DSC configuration scripts and supporting modules
PowerShell
10
star
81

SmartPackageProvider

A PackageManagement provider to find and install packages using search engines
C#
9
star
82

SystemLocaleDsc

DSC Resource for configuring Windows System Locale
PowerShell
8
star
83

xDisk

PowerShell
8
star
84

psl-pester

Fork of Pester for compatibility with PowerShell on Linux.
PowerShell
8
star
85

PowerShell-Blog-Samples

Samples for the PowerShell blog
PowerShell
7
star
86

ZLib

C
7
star
87

AWSBootStrapper

PowerShell
6
star
88

WSAProvider

A PackageManagement provider to find and install packages for Appx based packaging format
PowerShell
6
star
89

command-not-found

C#
6
star
90

PowerShellGetDsc

DSCResources for the PowerShellGet module
PowerShell
5
star
91

DscConfiguration.Tests

Test automation scripts for evaluating the quality of DSC Configurations using Azure virtual machines and Azure Automation DSC.
PowerShell
5
star
92

SILDeploymentHelper

PowerShell
4
star
93

vscode-powershellise-keybindings

A Visual Studio Code extension that configures PowerShell ISE keybindings.
TypeScript
4
star
94

PSPackageProject

PowerShell
4
star
95

Compliance

3
star
96

.github

3
star
97

ISEAddOnExamples

3
star
98

pscore-docs-dotnet

PowerShell
2
star
99

JsonAdapterFeedbackPredictor

1
star