powershell - 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:
- capsuleco.com (domain)
- CapsuleUsers (OU)
- NMUsers (OU)
- CapsuleUsers (OU)
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?
解决方案
推荐阅读
- amazon-web-services - 具有资源标签条件的 AWS Instance Connect
- android - 使用单个命令从多模块项目运行所有 UI/单元测试
- javascript - 编写单元测试用例时,箭头函数和普通函数有什么区别?
- javascript - Google Sheets API 适用于一张纸,但不适用于另一张
- python-3.x - 有没有更简单的方法可以将一串数字序列转换为python中的列表?
- c# - 首先在 EFCore 3.1.1 代码中播种数据后,是否可以将标识值设置为最后插入的 id + 1?
- python - 有没有办法将 numpy.extract 应用于 3d 数组?
- php - 运行“composer install”时如何指定使用特定的PHP版本?
- php - 检查php字符串是否仅包含来自欧洲语言的字符
- loops - groovy 映射意外的循环行为