Trying to figure out if there is an environment variable or another method to get a given machine's logon domain from simple command line script.
The variable %USERDOMAIN%
will provide me with the domain my user is - and in a domain trsut scenario does not return the machine's domain, rather MY domain.
The idea is that I want to be able to have my cmd script code not care about what domain it is in, but sitll be able to determine that info at runtime.
There's VBScript method here:
Set objRootDSE = GetObject("LDAP://RootDSE")
strDomain = objRootDSE.Get("DefaultNamingContext")
WScript.Echo strDomain
Another method is this:
net config workstation | findstr /C:"Workstation domain"
which outputs:
Workstation domain DOMAINNAME
But since there is no command line equivalent to unix cut
, I am finding it difficult to get this info into a variable.
This should do it for you:
Then
%machinedomain%
will contain the domain. Note that "Workstation domain" is case-sensitive there.Wmi:
Powershell: