How to Install And Configure PowerShell?

12 minutes read

PowerShell is a powerful scripting language and automation framework developed by Microsoft. It provides a command-line interface and scripting environment that allows users to automate tasks and manage computer systems. To install and configure PowerShell on your system, follow these steps:

  1. Check Windows Version: PowerShell is pre-installed on most modern Windows operating systems. Open the Start menu, type "PowerShell," and select "Windows PowerShell" or "PowerShell." If it opens, you already have PowerShell installed. If not, you need to install it.
  2. Downloading Windows Management Framework: If PowerShell is not already installed, you will need to download Windows Management Framework, which includes PowerShell. You can find the latest version on the Microsoft Download Center website.
  3. Choose the Right Version: Windows Management Framework includes different versions of PowerShell for different Windows versions. Make sure you select the one that corresponds to your operating system.
  4. Run the Installer: Once you have downloaded the appropriate Windows Management Framework package, locate the installer file and double-click on it to run it. Follow the on-screen instructions to complete the installation.
  5. Verify Installation: After the installation is complete, open the Start menu, type "PowerShell," and select "Windows PowerShell" or "PowerShell" to open the PowerShell command prompt. Alternatively, you can also open the command prompt and type "powershell" to launch PowerShell.
  6. Set Execution Policy (Optional): By default, PowerShell's execution policy only allows scripts signed by a trusted publisher to run. If you want to run scripts that you create or obtain from the internet, you may need to adjust the execution policy. To change the execution policy, open PowerShell as an administrator and use the command "Set-ExecutionPolicy " (replace with one of the available policy options like "Unrestricted" or "Bypass").
  7. Customize PowerShell Profile (Optional): PowerShell allows you to customize your experience by modifying its profile. The profile script is run every time you launch PowerShell, and you can add your own commands and configurations. To customize the profile, open PowerShell and use the command "notepad $profile" to open the profile script in Notepad. Add your desired commands, save the file, and close Notepad.


That's it! You have now installed and configured PowerShell on your system. You can start utilizing its powerful scripting capabilities to automate tasks and manage your computer systems efficiently.

Best PowerShell Books to Read in 2024

1
Mastering PowerShell Scripting: Automate and manage your environment using PowerShell 7.1, 4th Edition

Rating is 5 out of 5

Mastering PowerShell Scripting: Automate and manage your environment using PowerShell 7.1, 4th Edition

2
PowerShell Cookbook: Your Complete Guide to Scripting the Ubiquitous Object-Based Shell

Rating is 4.9 out of 5

PowerShell Cookbook: Your Complete Guide to Scripting the Ubiquitous Object-Based Shell

3
Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS

Rating is 4.8 out of 5

Learn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS

4
PowerShell for Sysadmins: Workflow Automation Made Easy

Rating is 4.7 out of 5

PowerShell for Sysadmins: Workflow Automation Made Easy

5
PowerShell for Beginners: Learn PowerShell 7 Through Hands-On Mini Games

Rating is 4.6 out of 5

PowerShell for Beginners: Learn PowerShell 7 Through Hands-On Mini Games

6
Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell

Rating is 4.5 out of 5

Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell

7
PowerShell Pocket Reference: Portable Help for PowerShell Scripters

Rating is 4.4 out of 5

PowerShell Pocket Reference: Portable Help for PowerShell Scripters


How to schedule PowerShell scripts using Windows Task Scheduler?

To schedule PowerShell scripts using Windows Task Scheduler, follow these steps:

  1. Open Task Scheduler: Press Win+R to open the Run dialog box. Type taskschd.msc in the box and click OK.
  2. In the Task Scheduler window, click on "Create Basic Task" or "Create Task" in the right-hand panel.
  3. Give your task a name and an optional description, then click Next.
  4. Choose the trigger for the task (e.g., daily, weekly, at log on, etc.) and click Next.
  5. Set the date and time for the task to start, and choose whether it will run daily, weekly, monthly, etc. Click Next.
  6. Select "Start a program" and click Next.
  7. In the "Program/script" field, provide the path to PowerShell by entering powershell.exe.
  8. In the "Add arguments" field, supply the path to your PowerShell script. For example, if your script is named script.ps1 and located in C:\Scripts, enter C:\Scripts\script.ps1.
  9. Click Next, review the summary, and click Finish.
  10. By default, the task will run under the credentials of the user who created it. If you want to change the user account, you can do so in the properties of the task.


Your PowerShell script is now scheduled to run according to your specified settings.


What are PowerShell modules and how to manage them?

PowerShell modules are self-contained units of PowerShell code that can be reused and shared across scripts and sessions. They contain functions, cmdlets, variables, and other resources that can be imported into a PowerShell session or script to extend its functionality.


To manage PowerShell modules, you can perform the following actions:

  1. Install a module: Use the Install-Module cmdlet to download and install a module from the PowerShell Gallery or a custom repository. For example: Install-Module -Name ModuleName.
  2. Import a module: Once a module is installed, use the Import-Module cmdlet to make its functionality available in your current PowerShell session or script. For example: Import-Module -Name ModuleName.
  3. Update a module: To update a module to the latest version, use the Update-Module cmdlet. For example: Update-Module -Name ModuleName.
  4. List installed modules: Use the Get-Module cmdlet to retrieve a list of all installed modules. For example: Get-Module.
  5. Remove a module: If you no longer need a module, use the Uninstall-Module cmdlet to remove it from your system. For example: Uninstall-Module -Name ModuleName.
  6. Discover available modules: You can search for available modules in the PowerShell Gallery or other repositories using the Find-Module cmdlet. For example: Find-Module -Name ModuleName.
  7. Import module automatically: If you want to automatically load a module each time you start a PowerShell session, you can add an Import-Module command to your PowerShell profile script. The profile script is executed every time a new PowerShell session starts.


By effectively managing PowerShell modules, you can enhance your PowerShell experience by leveraging pre-built functionality and saving time and effort in your scripts and tasks.


How to open PowerShell after installation?

To open PowerShell after installation, you can follow these steps:

  1. Press the Windows key on your keyboard or click on the Start button to open the Start Menu.
  2. Type "PowerShell" in the search bar located at the bottom left corner of the Start Menu.
  3. From the search results, you will see various options such as "Windows PowerShell", "Windows PowerShell (x86)", and "Windows PowerShell ISE" (Integrated Scripting Environment). Windows PowerShell: This is the standard version of PowerShell and is recommended for general use. Windows PowerShell (x86): Use this if you have a 32-bit version of Windows. Windows PowerShell ISE: This is an enhanced version with an integrated scripting environment that provides additional features for scripting.
  4. Click on the desired option based on your preference or requirements (e.g., "Windows PowerShell").
  5. The PowerShell window will now open, ready for you to start using.


How to update PowerShell to the latest version?

To update PowerShell to the latest version, you can follow these steps:

  1. Open an elevated PowerShell window. Right-click on the Start menu and choose "Windows PowerShell (Admin)".
  2. Run the following command to update PowerShellGet, which is a module used for managing PowerShell modules:
1
Install-Module -Name PowerShellGet -Force -AllowClobber


  1. Confirm any prompts that appear during the installation process.
  2. Once PowerShellGet is updated, run the following command to update PowerShell:
1
Update-Module -Name PowerShellGet -Force


  1. Confirm any prompts that appear during the update process.
  2. After the update is completed, restart the PowerShell session to start using the latest version.


You can verify the current PowerShell version by running the following command:

1
$PSVersionTable.PSVersion


This will display the installed PowerShell version, confirming if the update was successful.


How to download the latest version of PowerShell?

To download the latest version of PowerShell, follow these steps:

  1. Open a web browser and go to the Microsoft Download Center: https://aka.ms/PowerShell-Download
  2. On the PowerShell download page, you will see different options based on your operating system. Choose the appropriate option for your system, such as Windows, macOS, or Linux.
  3. Click on the "Download" button for the selected version. It will start downloading the installation package to your computer.
  4. Once the download is complete, locate the downloaded file and run it.
  5. Follow the on-screen instructions to install PowerShell on your computer.


Note: PowerShell 7 is the latest stable version as of now, which offers cross-platform support. If you are running Windows, you might also already have Windows PowerShell installed by default. PowerShell 7 can be installed side-by-side with Windows PowerShell without any conflicts.


How to pass command-line arguments to a PowerShell script?

To pass command-line arguments to a PowerShell script, you can follow these steps:

  1. Open the Windows Command Prompt or PowerShell.
  2. Use the powershell command to start a new PowerShell session.
  3. Specify the path to the PowerShell script file using the .ps1 file extension.
  4. Include any command-line arguments separated by spaces after the script path.


Here is an example of passing command-line arguments to a PowerShell script:

1
powershell C:\Scripts\MyScript.ps1 arg1 arg2 arg3


In your PowerShell script, you can access the passed arguments using the $args automatic variable. For example:

1
2
3
4
5
6
$arg1 = $args[0]
$arg2 = $args[1]
$arg3 = $args[2]
Write-Host "Argument 1: $arg1"
Write-Host "Argument 2: $arg2"
Write-Host "Argument 3: $arg3"


This script will print the values of the passed arguments to the console. You can modify the script to perform the desired actions based on the provided arguments.

Twitter LinkedIn Telegram Whatsapp

Related Posts:

To find the CPU and RAM usage using PowerShell, you can utilize various commands and methods. Here is how you can do it:Open PowerShell by pressing the Windows key, typing "PowerShell," and selecting "Windows PowerShell" or "PowerShell"...
To create a shortcut using PowerShell, you can follow these steps:Open PowerShell: Launch PowerShell by searching for it in the Start menu or by pressing Windows + X and selecting "Windows PowerShell" or "Windows PowerShell (Admin)." Create the...
To get an MD5 checksum in PowerShell, you can use the Get-FileHash cmdlet. Here's how you can do it:Open PowerShell by searching for it in the Start menu or by pressing the Windows key + X and selecting "Windows PowerShell" from the menu. In the Po...