How to Print an Existing Environment Variable using Power Shell in Microsoft Windows

Posted on

How to Print an Existing Environment Variable using Power Shell in Microsoft Windows

An existing environment variable can be printed in the Power Shell. Basically, there are already several existing environment variable available in the device running using Microsoft Windows as its operating system. It exist without having to define it in the Power Shell. The reason is because it has already been defined before so it is exist and it is already there. In other words, it is possible to print an environment variable which is already exist without having to define it first. Using a specific command will get the environment variable which already been registered.

Table of Contents

Introduction

As for the short explanation about this article, it will just explaining on how to print an existing environment variable. By running Power Shell exist in the device running using Microsoft Windows as its operating system while executing the right command, it will produce the intended output. That output will be an existing environment variables in the system.

How to Prepare for Printing an Existing Environment Variable using Power Shell in Microsoft Windows

For achieving that kind of purpose, below are the steps to follow in order :

  1. Just run the Power Shell which it will be the first step. So normally as one way to do it, just search the Power Shell link by pressing the Start button to display the textfield search. Type ‘Power Shell’ in the textfield search in order to search the Power Shell application.

  2. Next, click the suitable link for running Power Shell. After the Power Shell application is running, it will have the following appearance :

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

    Just print an existing environment variable in the Power Shell. Well, where is the name of the existing environment variable appear ?. Where does that environment variable’s name exist ?. Actually, in order to get list of existing environment variables, just print it first. Run the command ‘ls env:’ in order to print the available or the existing environment variable in the Power Shell. For further reference, just read the article in this link. It is an article with the title of ‘How to Print List Existing Environment Variable using Power Shell in Microsoft Windows‘.

  3. For printing an existing environment variable, below is the pattern or the format for doing it :

    $env:ENVIRONMENT_VARIABLE

    So, just use the above syntax pattern in order to print it in the Power Shell.

As it is said in the previous section, there is a syntax for printing an existing environment variable. In this case, before printing it, in order to know the name of the existing environment variable’s name, just get the list by typing ‘ls env:’ in the console of Power Shell. So, after knowing the name of the existing environment variable, print the value of it using the syntax format mentioned in the previous section. For an example, in order to print or to get the value of the JAVA_HOME environment variable which is already exist, just type the following command in the Power Shell console :

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>$env:JAVA_HOME
C:\Program Files\Java\jdk-17.0.2
PS C:\Users\Personal>

So, as it is shown above, there is an actual output appear. It is because it is already there The reason is because there is no prior definition or setting of an environment variable with the name of ‘JAVA_HOME’.

 

As for reference in another format, there is a video content showing how to do it. Just visit this link. Furthermore, as another way to see it, just view in the following embedded video :

Leave a Reply