Buy Me A Coffee 😇
Cover Image POWERSHELL: How to Reset When Changing System Environment Variables

POWERSHELL: How to Reset When Changing System Environment Variables

/ Resetting PowerShell after changing Windows system environment variables is essential to ensure that the updated variables take effect in the current session. When environment variables are modified, these changes may not be immediately reflected in running PowerShell sessions, potentially leading to inconsistencies or errors in script execution. Resetting PowerShell allows it to refresh and reload the updated environment variables, ensuring that subsequent commands and scripts operate with the correct and current configuration. This step is particularly crucial for tasks relying on specific environment variable values, such as file paths or system configurations, as it guarantees synchronization between the changes made and the PowerShell environment, thereby promoting accurate and reliable script execution.

Dec. 01, 2023. 6:30 AM

To Reset PowerShell whenever there is a change in your Windows system environment variable, edit your PowerShell profile.

First, we need to open our PowerShell in any terminal. If you're in Windows 10 or 11 you can use Windows Terminal. Then let us open our PowerShell profile using Notepad.

notepad $profile

That command will open your PowerShell profile in Notepad. We will then add a code in the end of our profile, like so:

# Reset Powershell ENV User and Machine Path variable so that PowerShell can find modules
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")

Your Done 😇 This way every time you update or add or change something on your System Environment Variables. PowerShell will reset and read those variables. You don't have to restart your machine; you can now only just restart your terminal instead.

What is a PowerShell?

PowerShell is a task automation framework and scripting language developed by Microsoft. It is designed specifically for system administrators and power users to automate tasks and manage configurations, both on local and remote Windows systems. PowerShell provides a command-line shell, a scripting language, and an associated scripting environment.

Key features of PowerShell include:

Cmdlets (Commandlets): Small, focused commands that perform specific tasks. Cmdlets follow a verb-noun naming convention, making them easy to understand and use.

Scripting Language: PowerShell is a full-fledged scripting language with variables, loops, conditionals, and functions. This allows users to create complex automation scripts.

Object-Oriented Pipeline: Cmdlets return objects, and these objects can be passed through a pipeline to perform additional actions. This makes it easy to chain commands together for more efficient scripting.

Remoting: PowerShell supports remote management, allowing administrators to execute commands on remote computers, making it a powerful tool for managing large-scale environments.

Integration with .NET: PowerShell is built on top of the .NET Framework, which means it can leverage .NET classes and assemblies, expanding its capabilities.

Extensibility: Users can create their own cmdlets, functions, and scripts to extend PowerShell's functionality. This makes it adaptable to a wide range of tasks and scenarios.

PowerShell is commonly used for tasks such as system administration, configuration management, and automation of repetitive tasks. It has become a vital tool in the Windows ecosystem and is also used in conjunction with other technologies like Desired State Configuration (DSC) for infrastructure as code.

Recommended PowerShell Version

PowerShell 7.x: This is the latest cross-platform version of PowerShell. It's open-source and works on Windows, macOS, and various Linux distributions. PowerShell 7.x introduces new features, improvements, and compatibility with earlier versions.

You can download PowerShell at Installing PowerShell on Windows - PowerShell | Microsoft Learn

It's important to check for the latest version at the time you're reading this, as Microsoft may have released newer versions since my last update. You can typically find the latest version on the official Microsoft PowerShell GitHub repository or the Microsoft website.

Always consider your specific needs and the features introduced in the latest version when deciding which version of PowerShell to use. Keep in mind that using a version that is too outdated may mean missing out on security updates and new functionalities.

As a programmer, PowerShell can be a valuable tool for several reasons:

Automation: PowerShell provides a powerful scripting language that allows you to automate a wide range of tasks. This includes repetitive administrative tasks, file manipulation, system configurations, and more. Automation can save time and reduce the risk of errors.

System Administration: For programmers working on Windows systems, PowerShell is an essential tool for system administration tasks. You can manage services, processes, registry settings, and other system-related configurations using PowerShell scripts.

DevOps Integration: PowerShell is commonly used in DevOps practices for tasks related to continuous integration, continuous deployment, and infrastructure as code. It helps streamline development workflows and ensures consistency across different stages of the software development life cycle.

Cloud Management: With its cross-platform capabilities, PowerShell is valuable for managing and automating tasks in cloud environments. This is particularly useful if you're working with cloud platforms like Microsoft Azure, AWS, or others.

Task Automation in Development Workflows: PowerShell scripts can be integrated into development workflows to automate various tasks. This might include tasks like database migrations, setting up development environments, or managing dependencies.

Data Processing and Analysis: PowerShell provides features for text processing, data manipulation, and simple scripting. It can be used for log analysis, parsing data, and performing basic data processing tasks.

Custom Tools and Utilities: Programmers can use PowerShell to create custom tools and utilities tailored to their specific needs. These tools can be shared with the team or community, contributing to the PowerShell ecosystem.

Cross-Platform Development: With PowerShell 7 being cross-platform, programmers working on different operating systems, such as Windows, Linux, or macOS, can use a consistent scripting language across environments.

Integration with Other Technologies: PowerShell integrates well with other Microsoft technologies and services. For example, it can be used to manage Active Directory, Exchange, SharePoint, and other Microsoft products.

Learning and Skill Development: Familiarity with PowerShell expands your skill set as a programmer. It provides you with another tool in your toolbox for solving problems and efficiently managing various aspects of your development environment.

If you enjoy this article and would like to show your support, you can easily do so by buying me a coffee. Your contribution is greatly appreciated!

Jenuel Ganawed Buy me Coffee