Setting system and user environment variables using Powershell in startup scripts

1) I used to set environment variables using group policy preferences, but then came SEP 12, which caused group policy client to freeze at stage “Setting Environment”

2)

When I used – or rather tried to use – cmd file in a startup script

set var1=mysetting1
set var2=mysetting2

the environment variables were not set though – they probably lived only in the cmd.exe process which died at the end of the script

3)

then I used Powershell or rathet .NET

 [Environment]::SetEnvironmentVariable(“TestVariable1”, “Test value1.”, “Machine”)

u can create user variables too – but that would probably go to the login script

 [Environment]::SetEnvironmentVariable(“TestVariable1”, “Test value1.”, “User”)

Advertisements

Tagged:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

smsagent

Tips, tricks and time-savers for the Windows and ConfigMgr administrator

To The Point

Anything about Technology and Business

Brian's Power Windows Blog

Microsoft in the Enterprise. Windows, Hyper-V, Exchange, SQL, and more!

PowerScripting Podcast

Shownotes and links for the PowerScripting Podcast, a podcast to help people learn Windows Powershell

Learn Powershell | Achieve More

What is this Powershell of which you speak?

%d bloggers like this: