2015年6月17日 星期三

Powershell Environment Variables




http://ss64.com/ps/syntax-env.html
https://technet.microsoft.com/en-us/library/ff730964.aspx

Environment Variables

Windows environment variables are visible as a PS drive called Env:

Get-ChildItem Env:

PowerShell Providers

In addition to environment variables, PowerShell providers also provide access to other data and components in a similar way - resembling a file system drive. This allows you to access many different types of data in a consistent way.
Built-in Providers
Alias - Windows PowerShell aliases {Alias}
Certificate - X509 certificates for digital signatures {cert}
Environment - Windows environment variables {Env}
FileSystem - File system drives, directories and files {filesystem}
Function - Windows PowerShell functions {Function}
Registry - Windows registry {HKLM, HKCU}
Variable - Windows PowerShell variables {Variable}

To create more permanent environment variables (i.e., user-level or machine-level) you need to use the .NET Framework and the SetEnvironmentVariable method. For example, this command creates a user-level environment variable named TestVariable:

[Environment]::SetEnvironmentVariable("TestVariable", "Test value.", "User")

以上需restart才有作用(存於Registry內)


Set-Item Env:TestVariable "Test Value2"

以上restart後資料會消失