##########################################
###### #将客户端主机移动到指定的OU内 ######
################# V1.0 #################
############ Yuanzhe #################
# # #添加 ActiveDirectory Power Shell Module # # #
Import-module ActiveDirectory
# # #将Windows7 Enterprise Edition assigned variable # # #
# # # # # $windows 7enterpise=get-adcomputer-searchbase "cn=computers,dc=ljstaff,dc=com"-filter {operatingsystem-eq " Windows 7 Enterprise Edition "}-properties operatingsystem,operatingsystemversion | Select Operatingsystem,operatingsystemversion
$windows 7enterpise = "Windows 7 Enterprise Edition"
# # #将Windows7 The Ultimate version of the variable # # #
$windows 7uitimate= "Windows 7 flagship Edition"
# # #将Windows10 Enterprise Edition assigned variable # # #
$windows 10enterpise= "Windows 10 Enterprise Edition"
# # #将Windows 10 Pro version gives variable # # #
$windows 10professionaledition= "Windows 10 Pro"
# # #查看computers目录下的所有计算机 # #
$computers =get-adcomputer-searchbase "cn=computers,dc=windows,dc=com"-filter *-properties operatingsystem, operatingSystemVersion
# # #添加域主机的OU目录 # #
$dasou = "Ou=das,dc=windows,dc=com"
foreach ($lscomputer in $computers)
{
# # #将computers The Windows 7 Enterprise computer under the OU moves to the DAS ou # # #
if ($lscomputer. Operatingsystem-eq "$windows 7enterpise") {
Move-adobject-identity $lscomputer-targetpath $dasou
# # #暂停 # #
#Pause
}
# # #将computers The Windows 7 Ultimate computer under the OU moves to the DAS ou # # #
if ($lscomputer. Operatingsystem-eq "$windows 7Uitimate") {
Move-adobject-identity $lscomputer-targetpath $dasou
# # #暂停 # #
#Pause
}
# # #将computers The Windows 10 Enterprise computer under the OU moves to the DAS ou # # #
if ($lscomputer. Operatingsystem-eq "$windows 10Enterpise") {
Move-adobject-identity $lscomputer-targetpath $dasou
# # #暂停 # #
#Pause
}
# # #将computers The Windows 10 Professional computer under the OU moves to the DAS ou # # #
if ($lscomputer. Operatingsystem-eq "$windows 10ProfessionalEdition") {
Move-adobject-identity $lscomputer-targetpath $dasou
# # #暂停 # #
#Pause
}
}
Make a task plan
Run the script every 4 hours
Adding parameters
Program script: PowerShell #运行工具
Add parameter: C:\script\Movecomputer.ps1 #脚本路径
Starting from: C:\script\ #指定程序目录
Move the client host to the specified OU