Powershell version, upgrade, enabling scripts execution, tips and tricks

Table of contents

Description

Windows PowerShell™ is a task-based command-line shell and scripting language designed especially for system administration. Built on the Microsoft .NET Framework, Windows PowerShell helps IT professionals and power users control and automate the administration of the Windows operating system and applications that run on Windows.

Determining installed version

To determine which version of Powershell is installed, open a command line window (cmd.exe) and use the following command:

C:\...> powershell -command "$PSVersionTable.PSVersion"


Major  Minor  Build  Revision

-----  -----  -----  --------

     0      -1     -1


(info) We can see here Powershell V4.0 is installed

Upgrading

Please see Microsoft Documentation pages here: Installing Windows PowerShell.

Enabling execution of Powershell scripts

To run PowerShell scripts (files that end with .ps1), you must first set the execution policy to Unrestricted. This operation has to be done once.

To do so, open a command line window (cmd.exe) as an Administrator and use the following command:

c:\Charon>powershell -command "Set-ExecutionPolicy Unrestricted"

(info) The ExecutionPolicy can also be set to "Remotesigned". In this case the .ps1 script files will have to be unblocked as described further.

For more, see Using the Set-ExecutionPolicy Cmdlet (Microsoft TechNet)

To check execution policy settings, use the following command:

c:\Charon>powershell -command "Get-ExecutionPolicy"

Unrestricted

For more, see Using the Get-ExecutionPolicy Cmdlet (Microsoft TechNet)

(blue star) In some cases, you will maybe have to unblock the .ps1 file for not being prompted to allow for execution:

c:\Charon>powershell -command "Unblock-File -path c:\charon\myscript.ps1"

List of Windows installed updates

C:\...> powershell

PS C:\...> get-hotfix >C:\Charon\Win_installed_updates.txt 

List of installed products

C:\...> powershell

PS C:\...> get-wmiobject -class win32_product >C:\Charon\Win_installed_products.txt


(warning) Requires the product is installed using standard settings. This will not list CHARON-AXP or CHARON-VAX for example but will list CHARON-AXP/SMA


Variant:

C:\...> powershell

PS C:\...> Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Format-Table –AutoSize


List of CHARON-AXP and CHARON-VAX products installed

Before version 4.8:

C:\...> powershell 

PS C:\...> Get-ItemProperty HKLM:\Software\Software_Resources_International\Build*\* | Select-Object Description, Installed, Product, ImagePath  | Format-Table –AutoSize


Starting version 4.8:

C:\...> powershell

PS C:\...> Get-ItemProperty HKLM:\Software\CHARON\Build*\* | Select-Object Description, Installed, Product, ImagePath  | Format-Table –AutoSize


Related articles



© Stromasys, 1999-2024  - All the information is provided on the best effort basis, and might be changed anytime without notice. Information provided does not mean Stromasys commitment to any features described.