将客户端主机移动到指定的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内

转载于:https://blog.51cto.com/8014597/2108742

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值