首页 > 解决方案 > Move an ADObject into a SubOU With Powershell

问题描述

I am trying to add users to SubOU's via PowerShell. The OU structure is as follows:

I have the following script for creating a new user in AD and adding them to the CapsuleUsers OU:

$name = Read-Host "User Name"
$email = Read-Host "Email"
$SAM = Read-Host "Sam Account Name"
$password = (Read-Host -AsSecureString "Account Password")

New-ADUser -Name $name -UserPrincipalName $name@capsuleco.com -DisplayName $name -SamAccountName $SAM -Email $email -Account Password $password

Get-ADUser $name | Move-ADObject -TargetPath "OU=CapsuleComputers, DC=capsuleco, DC=com"

This script works, it successfully adds a user to the CapsuleComputers OU. However, when I try add a user to a SubOU, such as the "NMUsers" OU, which resides within the CapsuleComputers OU via this method:

Get-ADUser $name | Move-ADObject -TargetPath "OU=CapsuleComputers, OU=NMUsers, DC=capsuleco, DC=com"

I get this error message:

"The operation could not be performed because the object's parent is either uninstantiated or deleted"

What is the easiest way to move an ADObject into a subOU?

标签: powershell

解决方案


推荐阅读