简体   繁体   English

如何在AD中搜索“计算机” OU中的名称,然后将这些计算机移至正确的位置?

[英]How do i search AD for names like the ones in the “Computers” OU and then move those computers over to their proper location?

I would like to search Active Directory for a computer with a name like WEB2309 that is currently in "Computers" OU then move it to where other computers have like names. 我想在Active Directory中搜索名称为WEB2309的计算机,该计算机当前位于“计算机” OU中,然后将其移至其他计算机具有相同名称的位置。

This what i have currently: 这是我目前拥有的:

Takes First member of Computers group 成为计算机组的第一位成员

$strFirstMember = get-adgroupmember "Computers"

Cuts off the last number of the first member 切断第一个成员的最后一个号码

$strFirstMember-1 = $strFirstMember.Substring(0,$strFirstMember.Length-1)

Searches for that on AD with a wildcard on the end to find like names 在广告末尾搜索通配符以查找类似名称

Get-ADObject -Filter { CN -like "$strFirstMember-1*" ObjectClass = "Computer"}

Now i need to move firstmember to the location that is found 现在我需要将firstmember移到找到的位置

The following will collect all your computer which match WEB230* and assign them to variable $c 以下内容将收集与WEB230 *匹配的所有计算机,并将它们分配给变量$ c

$c =  Get-AdComputer -Filter { CN -like "WEB230*"}

Moves all found computers to target OU 将找到的所有计算机移动到目标OU

$c | Move-ADObject -TargetPath "ou=YourOu,dc=domain,dc=com"

and this will move just the first one, I'm not sure if this is what you mean by "move firstmember.." 并且这将仅移动第一个成员,我不确定这是否就是您所说的“移动第一成员”。

 $c[0] | Move-ADObject -TargetPath "ou=YourOu,dc=domain,dc=com"

I personally prefer Quest Active Directory Cmdlets for AD scripting in Powershell. 我个人更喜欢Quest Active Directory Cmdlet在Powershell中进行AD脚本编写。

This would be the command I use for moves, from a collection of machines already built in a CSV file: 这将是我用于移动的命令,来自一组已内置CSV文件的机器:

Import-Csv "C:\toMove.csv" |`
    ForEach-Object {
    Get-QADComputer $_.Name |`
        Move-QADObject -NewParentContainer "OU=Computers,OU=Locked Computers,DC=com"
    }

In one step, you should be able to do something like this too: 第一步,您也应该可以执行以下操作:

$comparrisonPC = get-qadComputer "computerToUse"

get-qadComputers -Name "nameStructure*" |`
Where-Object {$_.CN -not $comparrisonPC.ParentContainerDN} |`
Move-QADObject -NewParentContainer "$comparrissonPC.ParentContainerDN"

I don't have a test domain to test it on, but it should work... 我没有要对其进行测试的测试域,但是它应该可以工作...

Building off what you already have, we get the computer, we strip the last character off of it, and then we get a list of all computers with a similar name. 利用已有的资源,获得计算机,从中删除最后一个字符,然后获得所有具有相似名称的计算机的列表。 Once we have that list I took a substring of it based off the DistinguishedName property, stripping the name out of it just leaving the OU path. 一旦有了该列表,我就根据DistinguishedName属性获取了它的子字符串,将其剥离出来只是留下了OU路径。 Then I grouped that, sorted the groupings by count to find the OU with the most computers in it with that similar name, and selected the first one. 然后,我将其分组,按计数对分组进行排序,以找到名称相同的计算机中拥有最多计算机的OU,然后选择第一个。 Then I told it to move the computer to that OU. 然后,我告诉它将计算机移至该OU。

$strFirstMember = get-adgroupmember "Computers"
$strFirstMember-1 = $strFirstMember.Substring(0,$strFirstMember.Length-1)
$Complist = Get-ADComputer -Filter { CN -like "$strFirstMember-1*" }
$NewOU = ($complist|%{$_.DistinguishedName.substring($_.DistinguishedName.indexof(",")+1,$_.DistinguishedName.length-$_.DistinguishedName.indexof(",")-1)}|group|sort count -Descending|select -first 1).name
Move-ADObject $strFirstMember -TargetPath $NewOU

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

相关问题 搜索登录到AD的OU内的多台计算机的用户的最快方法 - Fastest way to search for users logged into multiple computers within an OU of AD 如何使用WMI获取计算机的当前OU并列出该OU中的所有其他计算机? - How do I use WMI to get the current OU of a computer and list all other computers in that OU? 在每个AD OU中创建AD计算机组 - Creating AD Groups of computers in each AD OU 如何从计算机 OU 中动态移动计算机帐户 - How to dynamically move computer accounts from Computers OU 如何将各种组添加到OU中的计算机? - How to add various groups to the computers in OU? Powershell:查找AD中的所有计算机,但排除某些OU - Powershell: Find all computers in AD but exclude certain OU's Powershell脚本,用于将AD计算机与文本文件进行比较,并更改这些计算机上的注册表服务,然后编写脱机的计算机 - Powershell script to compare AD computers to text file and change registry service on those computer and then write the computers that were offline 如何在 Azure AD 中的计算机上发现已安装的软件 - How to discover installed software on Computers in Azure AD 如何将大量 AD 组从 OU 移动到其上层 OU? - How can I move a bulk of AD groups from an OU to its upper level OU? 嵌套IF,移动AD计算机 - Nested IF, moving AD computers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM