简体   繁体   English

如何找到远程加入 AD 的计算机的 DOMAIN\accountname$?

[英]How do I find DOMAIN\accountname$ of a remote AD-joined computer?

I want to store a remote computer's account name in a variable in the DOMAIN\Accountname format (preferably DOMAIN\Accountname$ . I know the DNS name and samaccountname of the computer, and I want to run the script on a domain-joined computer (not a domain controller).我想将远程计算机的帐户名存储在DOMAIN\Accountname格式的变量中(最好是DOMAIN\Accountname$ 。我知道计算机的 DNS 名称和 samaccountname,我想在加入域的计算机上运行脚本(不是域控制器)。

I cannot find any simple one-line approach to get the account name in that format.我找不到任何简单的单行方法来获取该格式的帐户名。 I can manually construct the string by concatenating the.NETBIOS domain name with computer name (samaccountname), but I was assuming there is an easier and more robust way of doing this.我可以通过将 .NETBIOS 域名与计算机名称 (samaccountname) 连接来手动构建字符串,但我假设有一种更简单、更可靠的方法可以做到这一点。

So is there any built-in approach of getting the computer name in the DOMAIN\Accountname$ format without having to manually constructing the string?那么是否有任何内置的方法可以以DOMAIN\Accountname$格式获取计算机名称而无需手动构造字符串? I assume that's common task.我认为这是常见的任务。

You can also look at the environmental variables.您还可以查看环境变量。 For this question, I would do the following...对于这个问题,我会做以下......

$strUserAndDomain = ((Get-Content env:userdomain) + "\" + (Get-Content env:username))

Then you can user the value of $strUserAndDomain whenever you want.然后您可以随时使用 $strUserAndDomain 的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM