MoveOU.ps1

something exciting

Some information about the exciting thing

Table of contents generated with markdown-toc


Script

#Created by Felipe Binotto
#On the 1st of September of 2010
#Move computer to required OU based on it's type

#Gets computer, model and type
$computer = (Get-WmiObject -Class Win32_ComputerSystem).name
$type = Get-WmiObject -Class Win32_SystemEnclosure | Select-Object -ExpandProperty ChassisTypes
#$model = Get-WmiObject -Class Win32_ComputerSystem | select -expandproperty model
$serial = (Get-WmiObject -Class Win32_SystemEnclosure | ForEach-Object {$_.serialnumber}).length

#Search the AD for the computer
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()

$search = [System.DirectoryServices.DirectorySearcher]$root
$search.Filter = "(cn=$computer)"
$result = $search.FindOne()
#Converts the result to the required format
$computerToMove = [ADSI]$result.path

#Move computer to required OU
Try{
if($type -eq 9 -or $type -eq 10){

$computerToMove.psbase.Moveto([ADSI]"LDAP://OU=Laptops,DC=domain,DC=com")}

elseif($type -eq 1 -or ($type -eq 3 -and $serial -gt 20)){

$computerToMove.psbase.Moveto([ADSI]"LDAP://OU=VDIs,DC=domain,DC=com")}

else{

$computerToMove.psbase.Moveto([ADSI]"LDAP://OU=Desktops,DC=domain,DC=com")}}
Catch{$error > C:\power.txt}

Back to Top


Download

Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.


Report Issues

You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.

Issue


Back to Top