Get the App
SLTechnology News&Howtos  ›  Servers  › 

Move the client host to the specified OU

Shulou Source: shulou.com Published: 2022-06-02 20:31:34 10月03日 Update

# #

# move the client host to the specified OU #

# V1.0 #

# yuanzhe #

# add ActiveDirectory power shell module #

Import-Module ActiveDirectory

# assign Windows7 Enterprise Edition to the variable #

# $windows7enterpise=Get-ADComputer-SearchBase "CN=Computers,DC=ljstaff,DC=com"-Filter {OperatingSystem-eq "Windows 7 Enterprise Edition"}-Properties OperatingSystem,OperatingSystemVersion | select OperatingSystem,OperatingSystemVersion

$windows7enterpise = "Windows 7 Enterprise Edition"

# assign the Windows7 flagship version to the variable #

$windows7Uitimate= "Windows 7 Ultimate Edition"

# assign the Windows10 Enterprise Edition to the variable #

$windows10Enterpise= "Windows 10 Enterprise Edition"

# assign Windows 10 Professional Edition to variables #

Windows10ProfessionalEdition= "Windows 10 Professional Edition"

# View all computers in the computers directory #

$computers=Get-ADComputer-SearchBase "CN=Computers,DC=windows,DC=com"-Filter *-Properties OperatingSystem,OperatingSystemVersion

# add OU directory of domain host #

$dasou= "ou=das,dc=windows,dc=com"

Foreach ($lscomputer in $computers)

{

# move the Windows 7 Enterprise Edition computer under computers OU to DAS OU #

If ($lscomputer.OperatingSystem-eq "$windows7enterpise") {

Move-ADObject-Identity $lscomputer-TargetPath $dasou

# pause #

# Pause

}

# move the Windows 7 Ultimate Edition computer under computers OU to DAS OU #

If ($lscomputer.OperatingSystem-eq "$windows7Uitimate") {

Move-ADObject-Identity $lscomputer-TargetPath $dasou

# pause #

# Pause

}

# move the Windows 10 Enterprise Edition computer under computers OU to DAS OU #

If ($lscomputer.OperatingSystem-eq "$windows10Enterpise") {

Move-ADObject-Identity $lscomputer-TargetPath $dasou

# pause #

# Pause

}

# move the Windows 10 professional version of the computer under computers OU to DAS OU #

If ($lscomputer.OperatingSystem-eq "$windows10ProfessionalEdition") {

Move-ADObject-Identity $lscomputer-TargetPath $dasou

# pause #

# Pause

}

}

Make a task plan

Run the script every 4 hours

Add parameter

Program script: powershell # run tool

Add parameters: C:\ script\ Movecomputer.ps1 # script path

Start with: C:\ script\ # specify the program directory

Tags: Enterprise Mobile computer variable Professional flagship Directory script Professional Edition Host Parameter Program run client client Task hour tool Module path Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS NVidia Shulou Tech Info Apple Huawei