将客户端主机移动到指定的OU内-成都快上网建站

将客户端主机移动到指定的OU内

##########################################
#######将客户端主机移动到指定的OU内######
################# V1.0 #################
############ yuanzhe #################

创新互联公司成立于2013年,是专业互联网技术服务公司,拥有项目成都网站制作、网站设计网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元库伦做网站,已为上家服务,为库伦各地企业和个人服务,联系电话:028-86922220

###添加 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内


文章名称:将客户端主机移动到指定的OU内
转载来于:http://kswjz.com/article/gcdicp.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流