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

來源:互聯網
上載者:User

標籤:將用戶端主機移動到指定的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內

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.