PSScriptAnalyzer | Download ScriptAnalyzer from PowerShellGallery | Command Line Interface library
kandi X-RAY | PSScriptAnalyzer Summary
kandi X-RAY | PSScriptAnalyzer Summary
PSScriptAnalyzer is a static code checker for PowerShell modules and scripts. PSScriptAnalyzer checks the quality of PowerShell code by running a [set of rules] docs/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 is shipped with a collection of built-in rules that checks various aspects of PowerShell code such as presence of uninitialized variables, usage of PSCredential Type, usage of Invoke-Expression etc. Additional functionalities such as exclude/include specific rules are also supported.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of PSScriptAnalyzer
PSScriptAnalyzer Key Features
PSScriptAnalyzer Examples and Code Snippets
Community Discussions
Trending Discussions on PSScriptAnalyzer
QUESTION
I want to know, why am I getting this message?
...ANSWER
Answered 2021-Nov-05 at 00:52This is a well-known false positive in PSScriptAnalyzer. You are not doing anything wrong.
You may disable it inline with a special attribute, like so:
QUESTION
I am currently developing a PowerShell script with 10k lines of code connecting to a SQL DB. While it is considered a best practice to use plug-ins in the IDE for example for Java or C# to scan the code (Resharper/ Fortify or Sonarcube plugin) and during the build process, perform a SAST analysis, I cannot find any tool suited for PowerShell code except the PSScriptAnalyzer which is good for bad smells but not so much considered a SAST tool.
Is such a tool currently simply not available for PowerShell or do you know any useful tools?
KR Chris
...ANSWER
Answered 2021-Aug-20 at 15:19NIST keeps a regularly updated list of SAST tool examples (not recommendations) here. As of August 20, 2021, the only tool that lists Powershell as a supported language is Atlassian's Static Reviewer:
Provides security checks in compliance with OWASP, CWE, CVE, CVSS, MISRA, CERT. Available as a module for Software Composition Analysis (SCA) to find vulnerabilities in open source and third party libraries
Personally, I just use the PSScriptAnalyzer
module with Microsoft's InjectionHunter ruleset. These days, you can add them to VSCode's powershell plugin rules.
QUESTION
I am trying to create a script to aid my helpdesk team when creating an AD Account. So far I am able to create a user account with a few attributes, however I am trying to make the script capable of filling all the required details out. What I would like to do is have a set list of locations and once a location is selected the script will use the variable $UserLocation in a range of functions, for now I just want the text returned ie; a user selects 'Location1' the variable $UserLocation returns the value 'Location1'. However at the moment it doesn't seem to work, I realise this is a really silly question but I can't figure it out for the life of me.
The area that has the issue is ##GetUserLocation The end result is to user $UserLocation to return the text selected in the combo box.
The Code I have so far is:
...ANSWER
Answered 2021-Mar-26 at 15:29Very nice UI, nicely done :)
Edit*On closer review, you had code to set $combobox1.add_SelectedIndexChanged
more than once, effectively removing the eventhandler I suggested in my previous answer. There was also a function that was in your code but not used at all, a ComboList helper. I trimmed your code down here and it now works fine.
Here's your issue. You are correctly setting up an event handler to trigger when a user changes the selected item in a combobox.
QUESTION
I want to publish my static analysis results via Nunit. I am doing so with Pester however this is set in configuration settings with Pester. Is there a way I can do the equivalent when using PS Script Analyzer? I can't find information about it on the documentation.
This is my current code:
...ANSWER
Answered 2021-Mar-04 at 09:11In Azure DevOps, we usually use Publish Test Results task to publish test results to Azure Pipelines. We can use the test runner of your choice that supports the results format you require. Supported results formats include CTest, JUnit (including PHPUnit), NUnit 2, NUnit 3, Visual Studio Test (TRX), and xUnit 2.
QUESTION
I have not been able to find any information on this so I'm not sure its entirely possible. I'm currently trying to integrate the WebView2 control into my PowerShell Winform GUI. I can see while debugging my script that the webView2 control is created, but nothing ever loads. I have the WebView2 runtime installed.
This is what I have so far:
...ANSWER
Answered 2021-Feb-09 at 07:14Trying out your code on my own I had to resolve two issues:
- From the webview2 nuget package (for reference I used the WebView2 nuget 1.0.781-prerelease package) I copied the winforms and core DLL from the net45 folder and I copied the x64 webview2loader.dll all into the wv2 folder. You need to ensure the webview2loader.dll of the appropriate CPU architecture is copied next to the core dll.
- The default WebView2 user data folder is in the folder containing the host executable. In this case the host executable is powershell and the containing folder isn't writable by normal processes. So you need to change the user data folder which you can do via the CoreWebView2CreationProperties UserDataFolder property before the WebView2 is initialized.
I have the modified code below. Additional work is required to resize and close the WebView2 and resolve other issues.
QUESTION
Let me start by saying I just started Azure and by no means a pro and been following guides here and there. So, I'm following this article by deploying this repo in my own Azure DevOps subscription, after I changed the resource group, subscription, and function name, I build and run the CI pipeline, then at the "Deploy Azure Resources" I'd get this error even though after the pipeline exits, the resources are created the way its supposed to, I also notice if I re run the same pipeline the 2nd time, it works perfectly which is confusing. Here is the modified the YAML template that I have
...ANSWER
Answered 2020-Dec-09 at 08:34The Resources are created yet the Deployment operation fails because there is a problem in caclulating the output variable.
Most likely it is because of the way you are trying to access the Service Principal Id of the App Service. The '/providers/Microsoft.ManagedIdentity/Identities/default' part.
You probably want something like this:
QUESTION
I have the following PowerShell cmdlet to install PowerShell module when the pipeline is being executed
...ANSWER
Answered 2020-Oct-31 at 23:37Edit:
Install-module
should be Install-Module
.
Moreover,by restoring the PSRespository back to default your problem is hopefully resolved :)
QUESTION
I have a code in my function that works well for me, was inspired by another SO answer, but is marked as improper in VSCode. I would like to improve on it, but currently I have no idea how.
...ANSWER
Answered 2020-Aug-10 at 14:24PSSA complains because the Mandatory
flag applies to the user - the user must specify arguments for all parameters marked Mandatory
in a parameter set - and since the user is already required to supply arguments, it makes no sense to default values, PowerShell will never use them.
The local variables corresponding to the switch parameters in the parameter sets NOT chosen will default to a $null
-like value, equivalent to $false
anyway:
QUESTION
I'm attempting to make a piece of software with a checkbox. It is supposed to do the following
- If checkbox is checked:
- Check if 'notepad' is running
- If not, launch 'notepad'
- Wait ~5 seconds and repeat
The code does as intended but it also freezes the windows form. I would like to avoid this. I have tried adding [System.Windows.Forms.Application]::DoEvents()
Between line 8 & 9 but to no avail
Raw code:
...ANSWER
Answered 2020-May-13 at 01:08You shouldn't be running a while loop from inside your checkbox event handler.
As soon as your form checks if the checkbox is checked, it'll freeze the form as it's on a single thread, and that thread is stuck in a while loop.
The CheckedChanged
handler should only really be used if you want something to run once when the checkbox changes state.
Functionality you want to run continuously based on the state of the checkbox could be done using a timer.
You could setup a timer like this:
QUESTION
So I'm trying to create a custom PsAnalyzer rule for the office, and it's my first time using $ast
based commands/variables. As a result I'm at a bit of a loss.
I've been using a couple of sites to get my head around the [System.Management.Automation.Language]
object class, namely this, this, and this.
For testing purposes I'm using the function below - dodgy looking params intended.
...ANSWER
Answered 2020-Apr-15 at 13:19Unlike an AssignmentStatementAst
, which has a Left
and Right
(-hand) value property, the ParameterAst
has a Name
and DefaultValue
property, so you'll want to use Name
in your predicate block:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install PSScriptAnalyzer
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page