Skip to main content
Active reading [<http://en.wikipedia.org/wiki/Windows_PowerShell>].
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

What is the proper way to set a user environment variable in a powershellPowerShell script?

I'm trying to schedule a command in a powershellPowerShell script to run using windowsWindows scheduler. This command relies on a user specific environment variable, and since scheduled tasks do not have access to these I have decided to try and just set the variable inside the powershellPowerShell script itself.

The normal environment variable configuration looks like this:   

enter image description hereEnter image description here

andAnd in order to replicate this in the script, I tried using:

$env:DCRCLIFILE = "C:\Users\pzsr7z\Desktop\DCRCLIFILE.txt"

butBut for some reason the program will not work properly when I set things up this way, even though it works perfectly fine when I run the program using the "normal" user environment variable.

Program execution using the powershellPowerShell initiated environment variable   

image descriptionImage description

Program execution using the "normal" environment variable:   

enter image description hereEnter image description here

Is there anything that I should be doing differently when setting the environment variable in the powershellPowerShell script? I'm not sure why this isn't working. I've verified that the environment variable actually gets created, so it's not like the powershellPowerShell command is failing.

What is the proper way to set a user environment variable in a powershell script

I'm trying to schedule a command in a powershell script to run using windows scheduler. This command relies on a user specific environment variable, and since scheduled tasks do not have access to these I have decided to try and just set the variable inside the powershell script itself.

The normal environment variable configuration looks like this:  enter image description here

and in order to replicate this in the script, I tried using:

$env:DCRCLIFILE = "C:\Users\pzsr7z\Desktop\DCRCLIFILE.txt"

but for some reason the program will not work properly when I set things up this way, even though it works perfectly fine when I run the program using the "normal" user environment variable.

Program execution using the powershell initiated environment variable  image description

Program execution using the "normal" environment variable:  enter image description here

Is there anything that I should be doing differently when setting the environment variable in the powershell script? I'm not sure why this isn't working. I've verified that the environment variable actually gets created, so it's not like the powershell command is failing.

What is the proper way to set a user environment variable in a PowerShell script?

I'm trying to schedule a command in a PowerShell script to run using Windows scheduler. This command relies on a user specific environment variable, and since scheduled tasks do not have access to these I have decided to try and just set the variable inside the PowerShell script itself.

The normal environment variable configuration looks like this: 

Enter image description here

And in order to replicate this in the script, I tried using:

$env:DCRCLIFILE = "C:\Users\pzsr7z\Desktop\DCRCLIFILE.txt"

But for some reason the program will not work properly when I set things up this way, even though it works perfectly fine when I run the program using the "normal" user environment variable.

Program execution using the PowerShell initiated environment variable 

Image description

Program execution using the "normal" environment variable: 

Enter image description here

Is there anything that I should be doing differently when setting the environment variable in the PowerShell script? I'm not sure why this isn't working. I've verified that the environment variable actually gets created, so it's not like the PowerShell command is failing.

Source Link
lacrosse1991
  • 3.2k
  • 8
  • 44
  • 50

What is the proper way to set a user environment variable in a powershell script

I'm trying to schedule a command in a powershell script to run using windows scheduler. This command relies on a user specific environment variable, and since scheduled tasks do not have access to these I have decided to try and just set the variable inside the powershell script itself.

The normal environment variable configuration looks like this: enter image description here

and in order to replicate this in the script, I tried using:

$env:DCRCLIFILE = "C:\Users\pzsr7z\Desktop\DCRCLIFILE.txt"

but for some reason the program will not work properly when I set things up this way, even though it works perfectly fine when I run the program using the "normal" user environment variable.

Program execution using the powershell initiated environment variable image description

Program execution using the "normal" environment variable: enter image description here

Is there anything that I should be doing differently when setting the environment variable in the powershell script? I'm not sure why this isn't working. I've verified that the environment variable actually gets created, so it's not like the powershell command is failing.