Get-EnvironmentVariable

Welcome Forums General PowerShell Q&A Get-EnvironmentVariable

Viewing 2 reply threads
  • Author
    Posts
    • #260559
      Participant
      Topics: 3
      Replies: 3
      Points: 47
      Rank: Member

      I would like to introduce a simple powershell script that can read and write environment variables:

      https://github.com/stax76/Get-EnvironmentVariable

      Normally I use the Windows GUI and invoke it like so:

      rundll32.exe sysdm.cpl,EditEnvironmentVariables

      Unfortunately the GUI is broken at 175% zoom. Meanwhile, I found a way to use it anyway with help of the powershell interface of AutoIt.

          Set-Location $PSScriptRoot
          Import-Module ..\..\Software\Dev\AutoIt\AutoItX
          rundll32.exe sysdm.cpl,EditEnvironmentVariables
          Start-Sleep 2
          Move-AU3Win 'Environment Variables' '' 0 -50 500 1000
    • #260562
      Senior Moderator
      Topics: 9
      Replies: 1373
      Points: 5,061
      Helping Hand
      Rank: Community MVP

      You don’t need to do UI automation. You [environment]::SetEnvironmentVariable() and [environment]::GetEnvironmentVariable() methods.

    • #260586
      Participant
      Topics: 3
      Replies: 3
      Points: 47
      Rank: Member

      I prefer the GUI, Get-EnvironmentVariable was written while the GUI did not work because the OK button was not visible on screen and there was no way to make it visible with mouse or keyboard. After Get-EnvironmentVariable was written I thought it’s likely easy to make the GUI usable, so I used AutoIt. Dealing with list variables like PATH I think Get-EnvironmentVariable is more convenient than any existing CLI solution.

      https://postimg.cc/jW6sM4J7

Viewing 2 reply threads
  • You must be logged in to reply to this topic.