locked
PowerShell MoveOU Script RRS feed

All replies

  • As the exception message says, there's a syntax problem preventing the MoveTo method from getting the expected arguments it needs. I'd recommend opening up the script in the PowerShell ISE, running it line by line, and examining the variables that get set to see where the issue is.

    https://ccmcache.wordpress.com/ | @kevmjohnston


    Wednesday, August 7, 2019 7:19 PM
  • Try this one. This joins the client to a domain and moves it to the correct OU:

    $domain = "[domain].[suffix]"
    $password = "[domainpassword]" | ConvertTo-SecureString -asPlainText -Force
    $username = "$[domain\[domainadmin]" 
    $credential = New-Object System.Management.Automation.PSCredential($username,$password)
    Add-Computer -DomainName $domain -Credential $credential -OUPath "OU=Desktops,OU=Maskiner,OU=[Site],DC=[domain],DC=[suffix]"

    As you can see, to move the client to the right OU you need to start with the lowest in the "hierarchy".

    I choose to place the clients inside the OU called Desktop, which again is placed inside the OU called Maskiner(OU for both desktops and laptops), which is placed inside the OU for site, and at the end the domain(domain.suffix)

    Hope this helps :)

    Friday, August 16, 2019 8:08 AM