How to Set Temporary Environment Variable using Power Shell in Microsoft Windows

Posted on

How to Set Temporary Environment Variable using Power Shell in Microsoft Windows

Setting environment variable temporarily is quite simple. For an example, use a Power Shell to set or to define it. It is necessary if the environment variable itself is an important thing for further process ahead. So, using the environment variable defined, the process which is using it can continue and running on further.

Table of Contents

Introduction

Using the running Power Shell available in the device which is running using Microsoft Windows as its operating system, just set the environment variable. After getting the Power Shell running, type the command for setting or defining the environment variable. Beside using Power Shell, it is also possible for doing it using Command Prompt. Just check the article with the title ‘How to Set Temporary Environment Variable using Command Prompt in Microsoft Windows’ in this link.

How to Set Temporary Environment Variable using Power Shell in Microsoft Windows

Obviously, the step will start by getting the Power Shell running. In that case, below are the steps to achieve it :

  1. So, as in the first step, just run the Power Shell. For running the Power Shell, just press the Start button. Then, textfield search will appear. In the textfield search, type ‘Power Shell’

  2. If there is a list containing results of the search process in the form of links, make sure to click the correct link. By clicking the right one, in this case it is ‘Power Shell’, it will run the Power Shell with the following appearance :

    How to Set Temporary Environment Variable using Power Shell in Microsoft Windows
    How to Set Temporary Environment Variable using Power Shell in Microsoft Windows
  3. For defining or setting an environment variable, below is the pattern or the format for doing it :

    $ENVIRONMENT_VARIABLE_NAME="ENVIRONMENT_VARIABLE_VALUE"

    For an example, below is the process for defining or setting an environment variable with the value of a certain path location. The example is defining the path of Gitlab repository path location as follows :

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
    
    PS C:\Users\Personal>$GITLAB_HOME="C:\Users\Personal\Documents\Gitlab"

By running the Command Prompt, it will provide an interface for the user to be able to execute several command for retrieving output which is the version of the existing or installed Python.

Checking the Environment Variable

After setting or defining the environment variable, just do the following to check the value or the content of the environment variable :

  1. Basically, just make sure that the previous Command Prompt executed is still running. In other words, the one where it contain the definition or the assignment process of the environment variable.  Below is the appearance of the Command Prompt will look like :

    It will then redirect the prompt for the normal prompt exist in Command Prompt to a Python command prompt. Below is the execution of the command :

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
    
    PS C:\Users\Personal>$GITLAB_HOME="C:\Users\Personal\Documents\Gitlab"
    
  2. Just continue on the process above for typing a command which is going to print the environment variable. It is an important step just to prove that the value of the environment variable is correct and also the syntax for defining the environment variable is also correct. Below is the syntax of the command for printing the environment variable :

    echo $ENVIRONMENT_VARIABLE_NAME

    So, using the above syntax pattern, below is the output continuing the previous step :

    Windows PowerShell
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
    
    PS C:\Users\Personal>$GITLAB_HOME="C:\Users\Personal\Documents\Gitlab"
    PS C:\Users\Personal>echo $GITLAB_HOME
    C:\Users\Personal\Documents\Gitlab
    PS C:\Users\Personal>
    

For more information about it, just check the video in this link. Either way, just watch it in the embedded video as follows :

Leave a Reply