How do I get the current username in Windows PowerShell?

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

How do I get the current username in Windows PowerShell?

15条回答
  •  半阙折子戏
    2020-11-28 01:52

    In my case, I needed to retrieve the username to enable the script to change the path, ie. c:\users\%username%\. I needed to start the script by changing the path to the users desktop. I was able to do this, with help from above and elsewhere, by using the get-location applet.

    You may have another, or even better way to do it, but this worked for me:

    $Path = Get-Location
    
    Set-Location $Path\Desktop
    

提交回复
热议问题