Skip to content

TechDirectArchive

Hands-on IT, Cloud, Security & DevOps Insights

  • Home
  • About
  • Advertise With US
  • Reviews
  • Contact
  • Toggle search form
Home » Scripts » How to perform PowerShell syntax check using PSScriptAnalyzer
  • updates
    How to stop Windows from applying updates Windows
  • Slide1 1
    How to manage Microsoft Defender Antivirus using Group Policy and Command Line Utility Anti-Virus Solution
  • MAP virtual disk error
    Install Workstation Pro 17: Fix failed to initialise library for mounting and unmounting virtual disks Virtualization
  • Prevent OS Reinstallation When Switching from Legacy BIOS to UEFI
    Prevent OS Reinstallation: Change from legacy BIOS to UEFI Windows
  • How to Fix Application Error (0xc0000135) in Windows
    Fix the application was unable to start correctly (0xc0000135) error Windows
  • WSUS Post deployment Configuration Failed
    The schema version of the database is from a newer version of wsus Windows Server
  • MBAM report errors
    Understanding MBAM compliance state and error status Windows
  • create a two way Active Directory Trust
    How to create a two-way Active Directory Trust Windows Server

How to perform PowerShell syntax check using PSScriptAnalyzer

Posted on 08/12/202030/12/2023 Christian By Christian No Comments on How to perform PowerShell syntax check using PSScriptAnalyzer
PowerShell syntax check

In this guide, we will discuss How to perform PowerShell syntax check using PSScriptAnalyzer. The PSScriptAnalyzer (PSSA) is an open-source tool that Microsoft developed. It is a static code checker for PowerShell modules and scripts. Here is a similar article on PowerShell debugging, Ansible Syntax Checker, how to debug a PowerShell script, how to install and debug logs with the CMTrace Tool, how to perform PowerShell syntax check using PSScriptAnalyzer, and Script debugging: Difference between testing and debugging.

It checks the quality of the PowerShell code by running against some set of rules that checks for potential code defects in the scripts by applying a group of built-in or customized rules on the scripts being analyzed. 

The default PSSA rules cover a wide variety of best practices, it checks your script, and warn you about using aliases instead of the full name of a command, using Invoke-Expression and other dangerous cmdlets, naming your functions correctly, and a whole lot more.

PowerShell syntax check using PSScriptAnalyzer

Note: You will have to set the execution policy. See these links for more information. Please see how to set the Execution Policy via Windows Settings, how to set the PowerShell Execution Policy. Also, see how to set PowerShell Execution Policy via the Registry.

Now, let’s install the PSScriptAnalyzer Module: The minimum PowerShell version you should be running is 3.0. See the link for more information. Install using any of the cmdlets below.

Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.11.0
Install-Module -Name PSScriptAnalyzer -Scope CurrentUser
PSScriptAnalyzer usage

You will be required to accept that you are okay with the installation of the PSScriptAnalyzer from an untrusted source “PSGallery”.

Nonetheless, The PowerShell Gallery is the central repository for PowerShell content. In it, you can find useful PowerShell modules containing PowerShell commands and Desired State Configuration (DSC) resources.

In addition, You can also find PowerShell scripts, some of which may contain PowerShell workflows and which outline a set of tasks and provide sequencing for those tasks. Consequently, Microsoft authors some of these packages, and others are authored by the PowerShell community.

Validate PowerShell scripts

Moreover, to verify this has been installed correctly, run the command below

Get-Module -Name PSScriptAnalyzer -ListAvailable
PowerShell script quality control

Note: Next, you will have to import the module in order to be able to use it. If you fail to import the module as shown below, you will get an error saying the command was found but the module could not be loaded.

Import-Module -Name PSScriptAnalyzer

PowerShell script testing with Invoke-ScriptAnalyzer

Furthermore, to test my script, I can run the “Invoke-ScriptAnalyzer”. The script takes a path to a directory and gets all the items that have been written more than the specified number of days ago.

However, You might be able to tell that this script has no problems already, just by looking at it. I have my random script saved as “MyScript.ps1“.

Invoke-ScriptAnalyzer -Path .\MyScript.ps1

PSSA even tells you the line of your script where the violation occurs and provides a more detailed description of the rule violation.

With the PSScriptAnalyzer installed, you could run your code through the Parser and observe if it raises an error.

I hope you found this blog post on how to perform PowerShell syntax check using PSScriptAnalyzer helpful. Please let me know in the comment session if you have any questions.

Rate this post

Thank you for reading this post. Kindly share it with others.

  • Share on X (Opens in new window) X
  • Share on Reddit (Opens in new window) Reddit
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Facebook (Opens in new window) Facebook
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Pocket (Opens in new window) Pocket
  • Share on Mastodon (Opens in new window) Mastodon
  • Share on Bluesky (Opens in new window) Bluesky
  • Share on Threads (Opens in new window) Threads
  • Share on Nextdoor (Opens in new window) Nextdoor
Scripts Tags:PowerShell, PowerShell version 7, PowerShellGet, Windows 10, Windows Server 2016

Post navigation

Previous Post: MDT Driver injection: How to import drivers in .exe format into Microsoft Deployment Toolkit
Next Post: How to update Printer Drivers on your Windows device

Related Posts

  • maxresdefault 2
    How to uninstall Applications with PowerShell Script Scripts
  • powershell commands lede 1024x276 1
    PowerShell Remoting: Guide to Windows Management Instrumentation Scripts
  • powershell logo
    Connecting to a remote server failed and WinRM cannot process the request: Error code 0x8009030e occurred while using Kerberos authentication, and a specified logon session does not exist Scripts
  • Generate SSH Keys
    Associate SSH Public key with Azure Linux VM AWS/Azure/OpenShift
  • PowerShell
    How to setup PowerShell on a Linux server Scripts
  • hero activedirectory
    Create and find Organisation Unit paths in AD Scripts

More Related Articles

maxresdefault 2 How to uninstall Applications with PowerShell Script Scripts
powershell commands lede 1024x276 1 PowerShell Remoting: Guide to Windows Management Instrumentation Scripts
powershell logo Connecting to a remote server failed and WinRM cannot process the request: Error code 0x8009030e occurred while using Kerberos authentication, and a specified logon session does not exist Scripts
Generate SSH Keys Associate SSH Public key with Azure Linux VM AWS/Azure/OpenShift
PowerShell How to setup PowerShell on a Linux server Scripts
hero activedirectory Create and find Organisation Unit paths in AD Scripts

Leave a Reply Cancel reply

You must be logged in to post a comment.

Microsoft MVP

VEEAMLEGEND

vexpert-badge-stars-5

Virtual Background

GoogleNews

Categories

veeaam100

sysadmin top30a

  • updates
    How to stop Windows from applying updates Windows
  • Slide1 1
    How to manage Microsoft Defender Antivirus using Group Policy and Command Line Utility Anti-Virus Solution
  • MAP virtual disk error
    Install Workstation Pro 17: Fix failed to initialise library for mounting and unmounting virtual disks Virtualization
  • Prevent OS Reinstallation When Switching from Legacy BIOS to UEFI
    Prevent OS Reinstallation: Change from legacy BIOS to UEFI Windows
  • How to Fix Application Error (0xc0000135) in Windows
    Fix the application was unable to start correctly (0xc0000135) error Windows
  • WSUS Post deployment Configuration Failed
    The schema version of the database is from a newer version of wsus Windows Server
  • MBAM report errors
    Understanding MBAM compliance state and error status Windows
  • create a two way Active Directory Trust
    How to create a two-way Active Directory Trust Windows Server

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,832 other subscribers
  • RSS - Posts
  • RSS - Comments
  • About
  • Authors
  • Write for us
  • Advertise with us
  • General Terms and Conditions
  • Privacy policy
  • Feedly
  • Telegram
  • Youtube
  • Facebook
  • Instagram
  • LinkedIn
  • Tumblr
  • Pinterest
  • Twitter
  • mastodon

Tags

AWS Azure Bitlocker Microsoft Windows PowerShell WDS Windows 10 Windows 11 Windows Deployment Services Windows Server 2016

Copyright © 2025 TechDirectArchive

 

Loading Comments...
 

You must be logged in to post a comment.