Switch to PSv7:
- Windows Server 2022 with Windows PowerShell 5.1 and PowerShell 7.2
- Windows Server 2019 with Windows PowerShell 5.1 and PowerShell 7.2
- macOS 11 with PowerShell Core 7.2
- Ubuntu 20.04 with PowerShell Core 7.2
Stores the installation directory for PowerShell. | |
Displays the profile values of Names, MemberType, and Paths. | |
Displays the profile values with wrapped text. | |
Displays only the Names of profile properties. | |
|
One of the challenges of writing PowerShell scripts is how to handle variables configuration, such as settings, paths, credentials, and other values that may vary depending on the environment or context. In this article, we will explore some best practices for managing variables configuration in a PowerShell project.
Get PowerShell version using | |
Shows all version and build information. | |
Get PowerShell version using | |
| Get PowerShell version in Command Prompt. |
Queries the installed versions of PowerShell using Common Information Model (CIM) and filters based on the product name:
Retrieves the PowerShell version as part of the operating system information using CIM:
Lists installed versions of PowerShell using (WMI):
"Name like 'Microsoft PowerShell%'"
Retrieves the PowerShell version as part of the operating system information using WMIC:
wmic os get PowerShellVersion
No scripts are allowed to run, offering the highest security level.
Useful for locked-down environments or when testing untrusted code.
Requires all scripts and configuration files, even those written locally, to be signed by a trusted publisher before execution.
Provides strong security but requires additional setup for signing your own scripts.
Permits execution of scripts downloaded from the internet only if they are signed by a trusted publisher.
Offers a balance between security and functionality, allowing some remote script execution.
No restrictions are in place, allowing all scripts to run without warnings or prompts.
Least secure option, use with caution only in trusted environments.
Sets the execution policy to the default for your system, which is:
Restricted for Windows client operating systems.
RemoteSigned for Windows server operating systems.
Subsystem
is not meant to change your default shell, quite the opposite – it defines a command that clients have to explicitly request. (It’s literally a server-side alias.)
So the configuration snippet you found wasn’t meant to change what you get from regular ssh
; it’s meant to allow a local PowerShell instance to invoke the SSH client and start a remote PowerShell on the server, without having to know its path (all it needs to specify is the subsystem name).
Specifically, the -sshs
option indicates that it’s meant for PSRemoting over SSH using the Enter-PSSession
or Invoke-Command
cmdlets, which can run via SSH in PowerShell 7.
PS> Enter-PSSession -HostName otherpc
[otherpc] PS>
(-HostName
option makes it use SSH, whereas -ComputerName
makes it use WinRM.)
(This won’t work in PowerShell 5 – its PSRemoting support can only run via WinRM, though if you want PowerShell then WinRM is actually not a bad alternative to SSH.)
Actually changing the default shell in Windows OpenSSH (the official Microsoft builds) is done completely differently – it’s documented on this page:
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" `
-Name DefaultShell `
-Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" `
-PropertyType String `
-Force
Ah, Monday morning dramas — the boss has that “we’ve got a problem” look plastered on their face. Surprise, surprise! You’re moving offices, and guess who’s got to wave their IT magic wand to make your network play nice with the existing setup? Oh yes, it’s you! But hold on — before you start thinking of visiting each computer individually like it’s 1999, let’s introduce you to PowerShell. I present a PowerShell method for configuring static and DHCP IP addresses that utilizes the newer PowerShell cmdlets.
Newer versions of PowerShell mean more cmdlets
Microsoft implemented more PowerShell cmdlets, including some cmdlets that are specific to configuring network adapters and TCP/IP settings.
Using these commands, we can set various network configurations and settings more easily from a PowerShell script.
If you have multiple network adapters, you need to identify which network adapter you wish to view or modify by name, interface index, status, etc. For systems with one adapter, you can typically get this by using only Get-NetAdapter with no extra parameters. Please adjust this to suit your environment.
This cmdlet gets you the network configuration (interfaces, IP addresses, and DNS servers).
The Get-NetIPInterface cmdlet gets you the IP interfaces, which can include both IPv4 and IPv6 addresses and their associated configurations. We will use just IPv4 today, so my example reflects that.
The Set-NetIPInterface allows you to modify settings.
This cmdlet lets you set the DNS servers associated with a particular network interface.
This cmdlet lets you modify IP routes in the routing table, including wiping out all routes.
This cmdlet allows you to create and configure an IP address. This can include both IPv4 and IPv6 addresses.
How to set static/DHCP IP addresses
Enough of the boring explanations. Let’s move on to the fun!
We’re going to give a couple of examples for setting static and DHCP IP addresses by using the commands mentioned above.
Set a static IP address
Set an address with DHCP
How to disable static/DHCP IP addresses
In PowerShell, you can manage network adapter settings to disable or enable static (manually assigned) and DHCP (automatically assigned) IP addresses using the Set-NetIPInterface cmdlet. The specific command depends on whether you want to disable static or DHCP addresses. Here are the PowerShell commands for each scenario:
Disable a static IP address
To disable a static IP address on a network adapter, you can set the interface to obtain an IP address automatically (DHCP). Here’s the PowerShell command:
Replace “YourNetworkAdapterName” with the actual name or alias of your network adapter. This command configures the interface to obtain an IP address automatically from a DHCP server.
Disable DHCP (obtain IP automatically) and enable a static IP address
Replace “YourNetworkAdapterName” with the actual name or alias of your network adapter, “YourStaticIPAddress” with the desired static IP address you want to assign, “YourSubnetPrefixLength” with the subnet prefix length (e.g., 24 for a typical subnet mask of 255.255.255.0), and “YourDefaultGatewayIP” with the IP address of your default gateway.
Final thoughts
This is still just scratching the surface of what’s available. Remember to check out what properties and methods are available for Win32_NetworkAdapterConfiguration, and you’ll be able to customize all the settings for your particular environment. For a more complete list of cmdlets you can use to set network and TCP/IP settings, check out our PowerShell Commands Library.
Jordan had spent his life wondering why tasks he didn’t like to do had no options to complete themselves. Eventually he had to make that happen on his own. It turned out that he enjoyed making tasks complete themselves, and PDQ thought that is something he should talk about on the internet.
If you run the same commands every time you launch the PowerShell console, then it’s probably time to customize your PowerShell profile for a smoother scripting experience.
When you develop a profile in PowerShell, you define your settings as a PowerShell script to make the process easier. In this article, learn about the PowerShell profile, how to edit your profile for any PowerShell console — the newer cross-platform PowerShell 7, Windows PowerShell 5.1, Visual Studio (VS) Code and PowerShell Integrated Script Environment (ISE) — and several handy additions for your profile.
What is the PowerShell profile?
The PowerShell profile is a PowerShell script that runs every time you launch PowerShell, except when you use the flag. The PowerShell profile location varies depending on several conditions:
- The version of PowerShell: Windows PowerShell or PowerShell 7?
- Is the profile for all users or the current user?
- Is the profile host application-specific?
- Windows PowerShell: $PSHOME\
- PowerShell 7:
- Windows: $PSHOME\
- Linux: /usr/local/Microsoft/powershell/7/
- macOS: /usr/local/Microsoft/powershell/7/
- Windows PowerShell: $HOME\Documents\WindowsPowerShell\
- PowerShell 7:
- Windows: $HOME\Documents\PowerShell\
- Linux: ~/.config/powershell/
- macOS: ~/.config/powershell/
The directories can have several valid profile files. The difference between the profiles is based on the host application that launches PowerShell. We use ISE and VS Code as examples for hosts:
- All hosts: profile.ps1
- ISE: Microsoft.PowerShellISE_profile.ps1
- VS Code: Microsoft.VSCode_profile.ps1
- All users, all hosts: $PSHOME\profile.ps1
- All users, VS Code: $PSHOME\Microsoft.VSCode_profile.ps1
- Current user, all hosts: $HOME\profile.ps1
- Current user, VS Code: $HOME\Microsoft.VSCode_profile.ps1
If any of those files don’t exist, PowerShell skips that profile.
How to access your PowerShell profile
The easiest way to retrieve the PowerShell profile is through PowerShell itself. You don’t need to remember the profile paths because they are stored in the variable.

$Profile | Get-Member -MemberType NoteProperty

$Profile.AllUsersAllHosts

$Profile.CurrentUserCurrentHost

code $Profile.CurrentUserCurrentHost
How to customize the PowerShell profile
Due to the PowerShell profile’s flexibility, you have a range of customization options to suit how you want PowerShell to work.
Customize your PowerShell prompt
We could dedicate a whole article to this topic and still not cover all the possibilities to modify the PowerShell prompt. If you aren’t familiar with customizing your PowerShell prompt, you can find many examples of cool prompts to see what’s possible. This article covers a basic example.
Function Prompt {
$endChar = '>'
# check if running as admin
If
(([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
$endChar = '#'
}
@"
$PWD
PS$endChar
"@
}
To make this function run every time PowerShell loads, put it in your profile.
How to load a PowerShell module and set defaults
A mistake that I regularly make is using a module that requires authentication before I’ve authenticated. Some of the modules have checks that remind you to authenticate, while others throw a cryptic error. If this problem occurs for a module you use frequently, then consider adding the authentication steps to your profile.
Connect-Graph
$graphUserProps = @(
'BusinessPhones',
'DisplayName',
'GivenName',
'Id',
'Mail',
'PreferredLanguage',
'Surname',
'UserPrincipalName'
)
Get-MgUser -UserId <upn> -Select ($graphUserProps + 'AccountEnabled','UsageLocation')
How to add aliases and argument completers
New-Alias -Name gmu -Value Get-MgUser
However, one of my favorite aliases is for kubectl, the Kubernetes command-line tool for working with clusters. I use the letter as my alias:
New-Alias -Name k -Value kubectl
How to add custom functions to your PowerShell profile
As you develop your PowerShell abilities, you might write more one-off functions to help with your work. But you might not feel the code is worth adding to a module. After you put your code in a source control platform, such as GitHub, then you can use dot sourcing to load the code when running PowerShell:
. C:\path\to\Function.ps1
This is just the start of what is possible. Start thinking about the commands you run frequently, and consider the other ways you can customize your PowerShell profile to make your life easier.
Anthony Howell is an IT expert who is well versed in multiple infrastructure and automation technologies, including PowerShell, DevOps, cloud computing, and the Windows and Linux OSes.
: To prevent the exploitation of Powershell.
: Improve security by watching for suspicious executions of Powershell.exe.
Enabled by Default: | No |
Platform: | Windows |
Minimum Agent Version Required: | 8.0.0 |
Rapid Config Settings
As with most rapid configs, you can:
Enable or disable the rapid config.
Specify what policies the rapid config applies to.
Invoke Expression
Use this group to protect against execution of powershell using the invoke-expression command line. Invoke-Expression is sometimes used by attackers to download and dynamically execute content.
- *Report Or Block Execution Of Powershell Using Invoke-Expression:
- Should execution of powershell using invoke-expression be reported or blocked? You should validate that legitimate execution is not blocked before enabling blocking.
- Report Execution Of Powershell Using Invoke-Expression:
- Carbon Black App Control will report or block execution of powershell using these command lines. You can add or remove items from this list. By default, the list includes:
- <CmdlineAnyArgument:iex>*
- <CmdlineAnyArgument:invoke-expression>*
- Invoke Expression Command Line Exceptions:
- Command lines that will not be reported or blocked. You can add or remove items from this list.
Downloads
Use this group to protect against execution of powershell using the download commands to download malicious files.
- *Report Or Block Execution Of Powershell Using Download Commands:
- Should execution of powershell using download commands be reported or blocked? You should validate that legitimate execution is not blocked before enabling blocking.
- Report Execution Of Powershell Using Download Commands:
- Carbon Black App Control will report or block execution of powershell using these command lines. You can add or remove items from this list. By default, the command list is as follows:
- <cmdline:*.downloadfile*>*
- <cmdline:*.downloadstring*>*
- <cmdline:*.downloaddata*>*
- Download Command Line Exceptions:
- Command lines that will not be reported or blocked. You can add or remove items from this list.
Execution Policy
Use this group to protect against powershell setting the ExecutionPolicy via the command line. The default policy is typically Restricted which only allows interactive powershell sessions and single command execution. Attackers can change the policy with the ExecutionPolicy parameter.
- *Report Or Block Execution Of Powershell Setting Bypass Or Unrestricted Execution Policy:
- Should execution of powershell with both the -hidden and -encoded parameters be reported or blocked? You should validate that legitimate execution is not blocked before enabling blocking.
- Report Execution Of Powershell Setting Bypass Or Unrestricted Execution Policy:
- Carbon Black App Control will report or block execution of powershell using these command lines. You can add or remove items from this list. By default, the following commands are listed:
- <cmdline:*-ex* bypass*>*
- <cmdline:*-ex* unrestricted*>*
- <cmdline:*-ep* bypass*>*
- <cmdline:*-ep* unrestricted*>*
- Execution Policy Command Line Exceptions:
- Command lines that will not be reported or blocked. You can add or remove items from this list.
Hidden and Encoded
Use this group to protect against powershell running in a hidden window and using an encoded command. Powershell attacks will often use the combination of encoded commands and hidden window styles to avoid detection.
- *Report Or Block Execution Of Powershell When The Command Line Contains Both -Hidden And -Encoded:
- Should execution of powershell with both the -hidden and -encoded parameters be reported or blocked? You should validate that legitimate execution is not blocked before enabling blocking.
- Report Execution Of Powershell When The Command Line Contains Both -Hidden And -Encoded:
- Carbon Black App Control will report or block execution of powershell using these command lines. You can add or remove items from this list. By default, the following is listed: <cmdline:*-e*><CmdlineAnyArgument:hidden>*
- Hidden And Encoded Command Line Exceptions:
- Command lines that will not be reported or blocked. You can add or remove items from this list.
WindowStyle
Use this group to protect against execution of powershell using -WindowStyle Hidden or WindowStyle -Minimized parameters. This can avoid powershell being hidden or minimized while performing malicious tasks.
- *Report Or Block Execution Of Powershell When The Command Line Contains WindowStyle Hidden Or Minimized:
- Should execution of powershell with WindowStyle hidden or minimized be reported or blocked? You should validate that legitimate execution is not blocked before enabling blocking.
- Report Execution Of Powershell When The Command Line Contains WindowStyle Hidden Or Minimized:
- Carbon Black App Control will report or block execution of powershell using these command lines. You can add or remove items from this list. By default, the list includes:
- <cmdline:*-w* Hidden*>*
- <cmdline:*-w* Minimized*>*
- Hidden Or Minimized Command Line Exceptions:
- Command lines that will not be reported or blocked. You can add or remove items from this list.
NoProfile
Use this group to protect against execution of powershell using the -NoProfile parameter. This can avoid powershell being run without using the profile scripts that have been put in place.
- *Report Or Block Execution Of Powershell When The Command Line Contains -NoProfile:
- Should execution of powershell with -NoProfile be reported or blocked? You should validate that legitimate execution is not blocked before enabling blocking.
- Report Execution Of Powershell When The Command Line Contains -NoProfile:
- Carbon Black App Control will report or block execution of powershell using these command lines. You can add or remove items from this list. By default, the following is listed:
- <cmdline:*-nop*>*
- NoProfile Command Line Exceptions:
- Command lines that will not be reported or blocked. You can add or remove items from this list.
Downgrade Attacks
Use this group to protect against powershell downgrade attacks. Downgrade attacks are when the attacker attempts to use an older, more vulnerable version of Powershell.
- *Report Or Block Execution Of Powershell When The Command Line Contains -Version:
- Should execution of powershell with -Version be reported or blocked? You should validate that legitimate execution is not blocked before enabling blocking.
- Report Execution Of Powershell When The Command Line Contains -Version:
- Carbon Black App Control will report or block execution of powershell using these command lines. You can add or remove items from this list. By default, the following is listed:
- <OnlyIf:RegKeyExists:hklm\SOFTWARE\Microsoft\PowerShell\3><cmdline:*-V*>powershell.exe
- Version Command Line Exceptions:
- Command lines that will not be reported or blocked. You can add or remove items from this list.
- *Report Or Block Execution Of Version 2 Instances Of System.Management.Automation.Dll:
- Should execution of version 2 instances of system.management.automation.dll by powershell be reported or blocked? Carbon Black App Control will block loading the dll by terminating powershell. You should validate that legitimate execution is not blocked before enabling blocking.
- Report Execution Of Version 2 Instances Of System.Management.Automation.Dll:
- Carbon Black App Control will report or block execution of powershell running older versions of System.Management.Automation*.dll. You can add or remove items from this list. The following listed by default:
- <OnlyIf:RegKeyExists:hklm\SOFTWARE\Microsoft\PowerShell\3>*\NativeImages_v2*\System.Management.Automation*.dll
- Version 2 Exceptions:
- Command lines that will not be reported or blocked. You can add or remove items from this list.
- *Report Or Block Execution Of The 32 Bit Version Of Powershell By The Specified Processes:
- Should execution of the 32 bit version of powershell by the specified processes be reported or blocked? Specifically, execution of 32 bit Powershell by 64 bit Powershell can indicate a downgrade attack. You should validate that legitimate execution is not blocked before enabling blocking.
- 32 Bit Powershell Instances To Report:
- Carbon Black App Control will report or block execution of 32 bit powershell instances by the specified processes. By default, the following is listed:
- <OnlyIf:ProcessorArchitecture:x64><Systemx86>\WindowsPowerShell\*\Powershell.exe
- Processes Not Allowed To Launch The 32 Bit Powershell:
- Carbon Black App Control will report or block execution of 32 bit powershell instances by the specified processes. By default, the following is listed:
- <OnlyIf:ProcessorArchitecture:x64><System>\WindowsPowerShell\*\Powershell.exe
- Command Lines That Will Not Be Blocked:
- Command lines specified here will not be blocked when starting a 32 bit instance of powershell.exe.
Execution Policy Registry Settings
Use this group to protect against modification of Powershell Execution Policy registry settings
- *Report Or Block Registry Modification:
- Should modification of the specified Powershell registry settings be reported or blocked? You should validate that legitimate registry modifications are not blocked before enabling blocking.
- Report Registry Modification:
- Carbon Black App Control will report or block modification of the specified registry settings. You can add or remove items from this list. The default entry is:
- HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ExecutionPolicy
- Processes Allowed To Modify The Specified Registry Settings:
- Processes specified here will be allowed to modify the specified registry settings. You can add or remove items from this list. The default entry is:
- <windows>\regedit.exe
Use Parameters
A third way to manage variables configuration is to use parameters. Parameters are arguments that are passed to a PowerShell script or function when it is invoked. Parameters allow you to specify input values for your script or function without hard-coding them in the code. You can define parameters for your script or function using the param
keyword at the beginning of the script or function body. For example:
# Use the parameters
Then, you can pass values to the parameters when you call the script or function. You can do this using various methods, such as:
- Using named parameters. For example:
- Using positional parameters. For example:
- Using splatting. Splatting is a way of passing a collection of parameter values to a script or function using a single variable. The variable can be an array, a hash table, or a custom object. For example:
# Define a hash table with parameter names and values
Using parameters has some advantages:
- It allows you to pass different configuration values to your script or function without modifying the code.
- It enables you to validate the parameter values using attributes such as
[ValidateSet]
,[ValidatePattern]
,[ValidateRange]
, etc. - It supports default values, mandatory values, dynamic values, and other features that make your script or function more flexible and robust.
However, using parameters also has some drawbacks:
- It may not be convenient or feasible to pass parameters for every configuration value you need.
- It may expose the configuration values in plain text on the command line, which may pose a security risk if they contain sensitive information such as passwords or keys.
- It may require you to write additional code to handle parameter binding, parsing, error handling, etc.
PowerShell Execution Policy
Lists all of the Scopes and ExecutionPolicies on the system. | |
Retrieves the current PowerShell execution policy using CMD. |
Queries the registry for the execution policy setting:
Retrieves the execution policy setting from the registry:
Generates an HTML report containing the Group Policy settings, including the PowerShell execution policy, and opens it in the default web browser:
h result.html && start result.html
Example scripts
You can also open the examples from the Command Palette ( (Windows, Linux )) with
the PowerShell: Open Examples Folder command.
Use Environment Variables
Another way to manage variables configuration is to use environment variables. Environment variables are variables that are defined by the operating system or by other applications and are available to all processes running on the system. PowerShell can access environment variables using the env:
drive, which is a special provider that exposes environment variables as a hierarchical namespace. For example, you can access the PATH
environment variable using $env:PATH
.
To use environment variables for your configuration values, you need to define them before running your PowerShell script. You can do this using various methods, such as:
- Using the
Set-Item
cmdlet on theenv:
drive. For example:
- Using the
setx
command-line tool. For example:
- Using the graphical user interface of your operating system. For example, on Windows 10, you can go to Settings > System > About > Advanced system settings > Environment Variables.
Using environment variables has some advantages:
- It avoids storing the configuration values in plain text files, which may improve security.
- It allows you to change the configuration values without modifying your PowerShell script or other scripts that use them.
- It enables you to have different configuration values for different users or sessions on the same system.
However, using environment variables also has some drawbacks:
- It may not be convenient or feasible to define environment variables for every configuration value you need.
- It may cause conflicts or errors if different scripts use environment variables with the same name but different meanings.
- It may not be portable across different systems or platforms that have different environment variables or naming conventions.
My favorite approach
For my project I would like to use a typical config file with a key-value-pair for each line.
Something like this:
tenantID=this is my tenant
clientID=client id
clientSecret=my secrets
tenantName=Contoso.com
There isn’t an official way to do that in PowerShell directly.
So, you have to create a small portion of code to load the config file content and set the variable names and values.
I created a function for a better approach and maintenance of the code.
In this foreach, the code set a variable with the same name of the config key and the value with everything in the row after the = character.
In order to use the variables in all the scripts in your project and modules, the script sets the scope as global.
Using the variables is very easy, you just need to add the dollar symbol on a variable with the same name of the config key.
From the previous example you can have:
$tenantID, $clientID and so on.
You can call the function Load-Config at the beginning of your script. In this case you can be sure that all the script and functions have access to the variables.
Additional resources
There are more detailed articles in the PowerShell documentation. Start with Using VS Code.
Check out the troubleshooting guide for answers to common questions.
Use a Configuration File
One of the simplest and most common ways to manage variables configuration is to use a configuration file. A configuration file is a PowerShell script that defines global variables that can be used by other scripts in the project. For example, you can create a file named Config.ps1
and put all your configuration variables in it, such as:
# Dot-source the configuration file# Use the configuration variables
Using a configuration file has some advantages:
- It separates the configuration from the logic, making the code more readable and maintainable.
- It allows you to change the configuration values without modifying the main script or other scripts that use them.
- It enables you to have different configuration files for different environments or scenarios, such as development, testing, production, etc.
However, using a configuration file also has some drawbacks:
- It exposes the configuration values in plain text, which may pose a security risk if they contain sensitive information such as passwords or keys.
- It requires you to manually copy or deploy the configuration file along with your main script or other scripts that use it.
- It may cause conflicts or errors if different scripts use different configuration files or define variables with the same name.
Installing the PowerShell extension
The PowerShell extension can be installed from the Visual Studio Code Marketplace by clicking the
Install Button. You can also install the PowerShell extension from within VS Code by opening
the Extensions view with keyboard shortcut (Windows, Linux ), typing PowerShell,
and selecting the PowerShell extension:
PowerShell extension settings
You can customize VS Code settings from the File > Preferences > Settings menu item.
You can also select the gear icon located in the lower left corner of the Activity Bar.
Types.ps1xml and Format.ps1xml files
- Syntax error reporting
- Schema validation
- Tag and attribute completion
- Autoclose tags
- Symbol highlighting
- Document folding
- Document symbols and outline
- Renaming support
- Document formatting
Major features
- Syntax highlighting
- Advanced built-in code snippets
- IntelliSense for cmdlets and more
- Problems reported by PowerShell Script Analyzer
- Go to Definition of cmdlets, variables, classes and more
- Find References of cmdlets, variables, classes and more
- Document and Workspace Symbol Navigation
- Symbol-based Outline View
- Run selected PowerShell code in current terminal using
- Launch online help for the symbol under the cursor using Ctrl + F1
- PowerShell Debugger integration
- An Extension Terminal that can interact with the debugger (try
Set-PSBreakpoint
!) - PowerShell ISE theme findable in the theme picker
- Also try ISE mode using (Windows, Linux ) then search for “Enable ISE Mode”
Debugging
Multi-version support
Or run the PowerShell: Show Session Menu command from the Command Palette
( (Windows, Linux )).
CodeLens support
CodeLenses are a VS Code feature to provide actionable, contextual information that’s displayed
within the source code.
CodeLens features include:
Pester Run tests and Debug tests.
Pester symbol support
Function, variable, class, and other symbol references
CodeLens reference support shows the number of times a symbol is referenced within your
code and allows you to jump to specific references.
PSScriptAnalyzer integration
The PowerShell extension includes PSScriptAnalyzer by default, and automatically performs
analysis on PowerShell script files you edit in VS Code.
PSScriptAnalyzer comes with a collection of built-in rules that check various aspects of
PowerShell source code such as presence of uninitialized variables, usage of PSCredential type,
usage of Invoke-Expression
, and others. The module also allows you to include or exclude specific
rules.
To disable PSScriptAnalyzer, open your settings ( (Windows, Linux )), browse
Extensions, select the PowerShell extension, and deselect the checkbox for Script
Analysis: Enable (powershell.scriptAnalysis.enable
).
PSScriptAnalyzer also provides code formatting. You can invoke automatic document formatting
with the Format Document command or the ( (Windows , Linux )) keyboard shortcut.
Pester integration
Plaster integration
Plaster is a template-based file and project generator written in PowerShell. Its purpose is
to streamline the creation of PowerShell module projects, Pester tests, DSC Configurations and more.
The PowerShell extension allows the creation of new Plaster projects using the PowerShell: Create
New Project from Plaster Template command from the Command Palette
( (Windows, Linux )).
Testing new features and providing feedback
If you find a bug, open an issue and revert to the stable version while we fix it.
Conclusion
Method | Security | Portability | Flexibility | Complexity |
---|---|---|---|---|
Configuration file | Low | Medium | High | Low |
Environment variable | High | Low | Medium | Medium |
Parameter | Medium | High | High | High |
Config File | High | High | High | High |
- Use descriptive and specific names for your configuration variables.
- Use Pascal case for your configuration variable names.
- Use standard parameter names or aliases for your script or function parameters.
- Use splatting to pass multiple parameter values to your script or function.
- Store sensitive information such as passwords or keys in secure locations such as Windows Credential Manager or Azure Key Vault.