Skip to content

USERDOMAIN Environmental Variable Returns COMPUTERDOMAIN Value #2407

@RamblingPSTech

Description

@RamblingPSTech

Environment: Windows Server in workgroup mode (not domain joined)

When logged into a Windows OS via Console, Remote Desktop, WinRM session, the %USERPROFILE% ($env:USERPROFILE) %USERDOMAIN% ($env:USERDOMAIN) variable contains the value of the computername (i.e. WIN-1DVQ9PPCF1L) - CORRECT

When logged into a Windows OS via SSH (direct SSH & PowerShell session over SSH), the %USERPROFILE% ($env:USERPROFILE) %USERDOMAIN% ($env:USERDOMAIN) variable contains the value of the workgroup name (i.e. "WORKGROUP") - INCORRECT

Processes that use a syntax of ${env(USERDOMAIN)}\${system_username} to reference a security principal fail when using a remote SSH session, but work with WinRM sessions due to the inconsistent USERDOMAIN value

Related Issues:


PowerShell Session Over WinRM

PS C:\> $pssessionoption = New-PSSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck
PS C:\> Enter-PSSession -SessionOption $PSSessionOption -ComputerName 192.168.0.10 -Credential (Get-Credential) -UseSSL

PowerShell credential request
Enter your credentials.
User: administrator
Password for user administrator: *********

[192.168.0.10]: PS C:\Users\Administrator\Documents> $env:userdomain
WIN-1DVQ9PPCF1L

PowerShell Session Over SSH

PS C:\> Enter-PSSession -HostName 192.168.0.10 -IdentityFilePath ~\.ssh\id_ecdsa -UserName administrator
[[email protected]]: PS C:\Users\Administrator\Documents> $env:userdomain
WORKGROUP

Expected behavior

Within Remote SSH session to Windows OS:

Command (cmd.exe): `echo %USERDOMAIN%`
Output: `WIN-1DVQ9PPCF1L` (current remote computer name)

Command (pwsh): `$env:userdomain`
Output:  `WIN-1DVQ9PPCF1L` (current remote computer name)

Actual behavior

Within Remote SSH session to Windows OS:

Command (cmd.exe): `echo %USERDOMAIN%`
Output: `WORKGROUP` (current NETBIOS workgroup name)

Command (pwsh): `$env:userdomain`
Output:  `WORKGROUP` (current NETBIOS workgroup name)

Error details

`${env(USERDOMAIN)}\${system_username}` is used by some processes to add the current user to the accesss control list after disabling inheritance and clearing existing access control entries.

WORKGROUP\USERNAME results in an invalid user SID mapping causing the Access Control List to have no Access Control Entries

Environment data

PSVersion                      7.5.4
PSEdition                      Core
GitCommitId                    7.5.4
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Version

OpenSSH_for_Windows_9.8p2 Win32-OpenSSH-GitHub, LibreSSL 4.0.0

Visuals

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions