PowerShell Config

Version

get-host | select-object Version

Get PowerShell version using get-host.

echo $PSVERSIONTABLE

Shows all version and build information.

$PSVersionTable.PSVersion

Get PowerShell version using $PSVersionTable.PSVersion.

powershell -command "$PSVersionTable.PSVersion"

Get PowerShell version in Command Prompt.

Queries the installed versions of PowerShell using Common Information Model (CIM) and filters based on the product name:

Get-CimInstance -ClassName Win32_Product -Filter "Name LIKE 'Microsoft PowerShell%'" | Select-Object -Property Name, Version

Retrieves the PowerShell version as part of the operating system information using CIM:

Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -Property PSVersion

Lists installed versions of PowerShell using (WMI):

wmic product where "Name like 'Microsoft PowerShell%'" get Name, Version 

Retrieves the PowerShell version as part of the operating system information using WMIC:

wmic os get PowerShellVersion

PowerShell Profiles

$PsHome

Stores the installation directory for PowerShell.

$Home

Stores the current user’s home directory.

$PROFILE

Stores the path to the current user's profile script.

ISE $profile

Opens the user's profile script in the Integrated Scripting Environment (ISE).

$PsHome\\Profile.ps1

Profile script for all users and all hosts.

$PsHome\\Microsoft.PowerShell_profile.ps1

Profile script for all users on the current host.

$Home\\[My]Documents\\Profile.ps1

Profile script for the current user and all hosts.

$Home\\[My]Documents\\WindowsPowerShell\\Profile.ps1

Profile script for the current user on the current host.

$profile | Get-Member -Type NoteProperty

Displays the profile values of Names, MemberType, and Paths.

$Profile | get-member -type noteproperty | ft -wrap

Displays the profile values with wrapped text.

$PROFILE | Get-Member -MemberType noteproperty | select name

Displays only the Names of profile properties.

Test-Path -Path $profile.currentUsercurrentHost

Checks if the profile for the current user and host exists.

Test-Path -Path $profile.currentUserAllHosts

Checks if the profile for the current user and all hosts exists.

Test-Path -Path $profile.AllUsersAllHosts

Checks if the profiles for all users and all hosts exist.

Test-Path -Path $profile.AllUserscurrentHost

Checks if the profiles for all users on the current host exist.

New-Item -ItemType File -Path $profile -Force

Creates a new profile script for the current user, ignoring errors.

Switch Versions

Switch to PSv7:

pwsh

PowerShell Execution Policy

Get-ExecutionPolicy -list

Lists all of the Scopes and ExecutionPolicies on the system.

Get-ExecutionPolicy

Gets the current user's ExecutionPolicy.

powershell.exe Get-ExecutionPolicy

Retrieves the current PowerShell execution policy using CMD.

Sets the ExecutionPolicy for the CurrentUser to Unrestricted:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope CurrentUser 

Queries the registry for the execution policy setting:

reg query "HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" /v ExecutionPolicy

Retrieves the execution policy setting from the registry:

Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" -Name ExecutionPolicy

Generates an HTML report containing the Group Policy settings, including the PowerShell execution policy, and opens it in the default web browser:

gpresult /h result.html && start result.html

Notes

Restricted: No scripts are allowed to run, offering the highest security level. Useful for locked-down environments or when testing untrusted code.

AllSigned: 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.

RemoteSigned: 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.

Bypass: No restrictions are in place, allowing all scripts to run without warnings or prompts. Least secure option, use with caution only in trusted environments.

Default: Sets the execution policy to the default for your system, which is: Restricted for Windows client operating systems. RemoteSigned for Windows server operating systems.

Last updated

Was this helpful?