Remotely grabbing username

Welcome Forums General PowerShell Q&A Remotely grabbing username

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
4 years, 4 months ago.

  • Author
    Posts
  • #17296

    Participant
    Points: 0
    Rank: Member

    I am using Get-item env:\username and I would only like to grab the value so I can set it to $strname

    PS C:\Users\testuser> Get-Item env:\username

    Name Value
    —- —–
    USERNAME testuser

    Thank you for assistance.

  • #17297

    Participant
    Points: 0
    Rank: Member

    I was able to figure it out.
    Thank you

  • #17298

    Member
    Points: 0
    Rank: Member

    For environment variables, there's a shortcut syntax:

    $env:username
    

    I'm not sure where "Remotely" comes into this question, though.

  • #17320

    Participant
    Points: 76
    Rank: Member
    $strName = (Get-Item -Path Env:\USERNAME).value
    

The topic ‘Remotely grabbing username’ is closed to new replies.