I have a user object from Active Directory that has properties like distinguished name. I can easily get the domain portion from that, like dc=somedomain,dc=com. If it were the local domain, I could use Powershell: (get-addomain -Identity "dc=mydomain,dc=com").netbiosname to get the short name. But for this external trusted domain, that doesn't work because it just searches within the local domain. Does anyone know of another way to use Powershell to get the short name for the domain of an arbitrary AD user/group?
You just need to add the
-Server
argument to yourGet-ADDomain
call that specifies a DC in that forest. If you were on a non-domain joined machine, you could add-Credential
to explicitly provide credentials as well. But hypothetically, your trust will pass along your current credentials automatically.So the new command would look like this:
You can also combine it with
Get-ADDomainController
if you don't already know a DC for the target domain.I know this is an old post, but this is a quicker way: