1. 程式人生 > >將客戶端主機移動到指定的OU內

將客戶端主機移動到指定的OU內

將客戶端主機移動到指定的OU內

##########################################
#######將客戶端主機移動到指定的OU內######
################# V1.0 #################
############ yuanzhe #################

###添加 ActiveDirectory power shell模塊###
Import-Module ActiveDirectory
###將Windows7 企業版賦予變量###
####$windows7enterpise=Get-ADComputer -SearchBase "CN=Computers,DC=ljstaff,DC=com" -Filter {OperatingSystem -eq "Windows 7 企業版"} -Properties OperatingSystem,OperatingSystemVersion | select OperatingSystem,OperatingSystemVersion

$windows7enterpise ="Windows 7 企業版"

###將Windows7 旗艦版賦予變量###
$windows7Uitimate="Windows 7 旗艦版"

###將Windows10 企業版版賦予變量###
$windows10Enterpise="Windows 10 企業版"

###將Windows 10 專業版版賦予變量###
$windows10ProfessionalEdition="Windows 10 專業版"

###查看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 OU下的Windows 7 企業版計算機移動到 DAS OU內###
if ($lscomputer.OperatingSystem -eq "$windows7enterpise"){
Move-ADObject -Identity $lscomputer -TargetPath $dasou
###暫停###
#Pause
}
###將computers OU下的Windows 7 旗艦版計算機移動到 DAS OU內###

if ($lscomputer.OperatingSystem -eq "$windows7Uitimate"){
Move-ADObject -Identity $lscomputer -TargetPath $dasou
###暫停###
#Pause
}
###將computers OU下的Windows 10 企業版計算機移動到 DAS OU內###
if ($lscomputer.OperatingSystem -eq "$windows10Enterpise"){
Move-ADObject -Identity $lscomputer -TargetPath $dasou
###暫停###
#Pause
}
###將computers OU下的Windows 10 專業版計算機移動到 DAS OU內###
if ($lscomputer.OperatingSystem -eq "$windows10ProfessionalEdition"){
Move-ADObject -Identity $lscomputer -TargetPath $dasou
###暫停###
#Pause
}
}

制作任務計劃

每隔4小時運行一下腳本

添加參數
程序腳本:powershell #運行工具
添加參數:C:\script\Movecomputer.ps1 #腳本路徑
起始於:C:\script\ #指定程序目錄

技術分享圖片

將客戶端主機移動到指定的OU內