{"id":30682,"date":"2022-07-22T20:42:59","date_gmt":"2022-07-22T20:42:59","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=30682"},"modified":"2022-12-23T05:52:17","modified_gmt":"2022-12-23T05:52:17","slug":"a-fundamental-tutorial-of-psscriptanalyzer","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/a-fundamental-tutorial-of-psscriptanalyzer\/","title":{"rendered":"A Fundamental Tutorial of PSScriptAnalyzer"},"content":{"rendered":"\n<p><strong>PSScriptAnalyzer is a static code checker for PowerShell modules and scripts. PSScriptAnalyzer checks the quality of PowerShell code by running a set of rules.<\/strong><\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>PSScriptAnalyzer ships with a collection of built-in rules that check various aspects of PowerShell code such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The presence of uninitialized variables<\/li><li>Use of PSCredential type<\/li><li>Use of Invoke-Expression<\/li><li>And many more<\/li><\/ul>\n\n\n\n<p>You can choose which rules to include or exclude for your modules and scripts. PSScriptAnalyzer also has the ability to fix the formatting of your code. This helps you produce code that conforms to a standard style, is easier to read, and is more maintainable.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to Install PSScriptAnalyzer?<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Method 1 &#8211; Using Install-Module<\/h3>\n\n\n\n<p>$ Install-Module -Name PSScriptAnalyzer -Force<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Mehtod 2 &#8211; Using Install-PSResource<\/h3>\n\n\n\n<p><strong>Step 1-<\/strong> Install PowerShellGet using follwing tutorials<\/p>\n\n\n\n<p><strong>Step 2 &#8211;<\/strong> Run following command<br>$ Install-PSResource -Name PSScriptAnalyzer -Reinstall<\/p>\n\n\n\n<p>More Info &#8211; <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/utility-modules\/psscriptanalyzer\/overview?view=ps-modules\">https:\/\/docs.microsoft.com\/en-us\/powershell\/utility-modules\/psscriptanalyzer\/overview?view=ps-modules<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">PSScriptAnalyzer Commands<\/h2>\n\n\n\n<p>$ Get-ScriptAnalyzerRule<br>Gets the script analyzer rules on the local computer.<\/p>\n\n\n\n<p>$ Invoke-Formatter<br>Formats a script text based on the input settings or default settings.<\/p>\n\n\n\n<p>$ Invoke-ScriptAnalyzer<br>Evaluates a script or module based on selected best practice rules<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PSScriptAnalyzer is a static code checker for PowerShell modules and scripts. PSScriptAnalyzer checks the quality of PowerShell code by running a set of rules. PSScriptAnalyzer is a&#8230; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[2],"tags":[],"class_list":["post-30682","post","type-post","status-publish","format-standard","hentry","category-uncategorised"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=30682"}],"version-history":[{"count":1,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30682\/revisions"}],"predecessor-version":[{"id":30683,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/30682\/revisions\/30683"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=30682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=30682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=30682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}