Display all environment variables from a running PowerShell script

前端 未结 5 988
猫巷女王i
猫巷女王i 2020-12-12 18:37

I need to display all configured environment variables in a PowerShell script at runtime. Normally when displaying environment variables I can just use one of the following

相关标签:
5条回答
  • 2020-12-12 19:14

    Shorter version:

    gci env:* | sort-object name
    

    This will display both the name and value.

    0 讨论(0)
  • 2020-12-12 19:21

    Shortest version (with variables sorted by name):

    gci env:
    
    0 讨论(0)
  • 2020-12-12 19:21

    I don't think any of the answers provided are related to the question. The OP is getting the list of Object Types (which are the same for each member) and not the actual variable names and values. This is what you are after:

    gci env:* | select Name,Value
    

    Short for:

    Get-ChildItem Env:* | Select-Object -Property Name,Value
    
    0 讨论(0)
  • 2020-12-12 19:27

    I finally fumbled my way into a solution by iterating over each entry in the dictionary:

    (gci env:*).GetEnumerator() | Sort-Object Name | Out-String
    
    0 讨论(0)
  • 2020-12-12 19:27

    Short version with a wild card filter:

    gci env: | where name -like 'Pro*'
    
    0 讨论(0)
提交回复
热议问题