moving PC to new OU not working
i need run script on workstations. script run @ workstation service tech. there no rsat tools. i need make script move machine run new ou in ad. i have code.
$computer = get-content env:computername
$getou = 'ou=clinical,ou=main campus,ou=workstations,dc=acme,dc=org'
$dom = [system.directoryservices.activedirectory.domain]::getcurrentdomain()
$root = $dom.getdirectoryentry()
$search = [system.directoryservices.directorysearcher]$root
$search.filter = "(cn=$computer)"
$result = $search.findone()
$computertomove = [adsi]$result.path
$computertomove
$computertomove.psbase.moveto([adsi]"ldap://$getou")
when run code following error.
exception calling "moveto" "1" argument(s): "there no such object on server.
i've run on workstation , know in ad. in fact put print-statement after each variable above , every line of code works , shows me machine is. it last line fails. how come? when workstation exist how come can't find it?
mqh7
i found code doing google search , worked.
$computers = (get-wmiobject -class win32_computersystem).name$dom = [system.directoryservices.activedirectory.domain]::getcurrentdomain()
$root = $dom.getdirectoryentry()
foreach($computer in $computers){
$search = [system.directoryservices.directorysearcher]$root
$search.filter = "(cn=$computer)"
$result = $search.findone()
$computertomove = [adsi]$result.path
$computertomove.psbase.moveto([adsi]"ldap://ou=clinical,ou=workstations,dc=acme,dc=org")}
mqh7
Windows Server > Windows PowerShell
Comments
Post a Comment