How do I get the current username in Windows PowerShell?

后端 未结 15 2779
被撕碎了的回忆
被撕碎了的回忆 2020-11-28 01:35

How do I get the current username in Windows PowerShell?

15条回答
  •  没有蜡笔的小新
    2020-11-28 02:13

    Now that PowerShell Core (aka v6) has been released, and people may want to write cross-platform scripts, many of the answers here will not work on anything other than Windows.

    [Environment]::UserName appears to be the best way of getting the current username on all platforms supported by PowerShell Core if you don't want to add platform detection and special casing to your code.

提交回复
热议问题