gpt4 book ai didi

powershell - 在不使用 ActiveDirectory 模块的情况下在 powershell 中获取当前计算机的可分辨名称

转载 作者:行者123 更新时间:2023-12-04 01:53:31 24 4
gpt4 key购买 nike

我有一个脚本,我需要找到运行它的计算机的完整专有名称 (CN=MyComputer, OU=Computers, DC=vw, DC=local),但是我不能保证 ActiveDirectory模块将在运行此脚本的所有计算机上可用。有没有办法在不使用 Get-ADComputer $Env:COMPUTERNAME 的情况下获取当前计算机的完整专有名称? ?

以防万一这是一个 XY 问题,我想要做的是将计算机移动到特定的 OU,但我需要一种方法来获取我正在运行的计算机的 ASDI 条目。

[ADSI]$computer = ("LDAP://" + $localDN)
if($Production)
{
[ADSI]$destination = 'LDAP://ou=Production,ou=Computers,ou=VetWeb,dc=vw,dc=local'
$computer.MoveTo($destination);
}
else
{
[ADSI]$destination = 'LDAP://ou=Test,ou=Computers,ou=VetWeb,dc=vw,dc=local'
$computer.MoveTo($destination);
}

最佳答案

试试这个(需要 v2):

$filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$env:COMPUTERNAME))"
([adsisearcher]$filter).FindOne().Properties.distinguishedname

关于powershell - 在不使用 ActiveDirectory 模块的情况下在 powershell 中获取当前计算机的可分辨名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11146264/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com