简体   繁体   English

通过 powershell 将多个组的管理更改为用户的管理员

[英]Change multiple group's managed by to user's manager by powershell

I'm very new in powershell. I'm trying to create a script to disable the AD account and do multiple tasks in it.我是 powershell 的新手。我正在尝试创建一个脚本来禁用 AD 帐户并在其中执行多项任务。

I'm stuck in the part where i want to assign all the Distribution lists and Security Groups managed by the user to his manager.我被困在我想将用户管理的所有分发列表和安全组分配给他的经理的部分。 Below is the script, any help would be appreciated.下面是脚本,任何帮助将不胜感激。

$SamAccountName = Read-Host "Enter the username"
$ManagedObjects = Get-ADUser $SamAccountName -Properties managedObjects |select -ExpandProperty managedObjects
$Manager = Get-ADUser $SamAccountName -Properties manager | Select -ExpandProperty Manager
$ManagedObjects |  ForEach-Object {
    Set-ADGroup -Identity $_.Group -ManagedBy ($Manager.DistinguishedName)
}

I have tested in my environment.我已经在我的环境中进行了测试。

You can use the below PowerShell script to change multiple group's managed by to user's manager:您可以使用以下 PowerShell 脚本将多个组的管理更改为用户的管理员:

$SamAccountName = Read-Host "Enter the username"
$ManagedObjects = Get-ADUser $SamAccountName -Properties managedobjects | select -ExpandProperty managedObjects
$Manager = Get-ADUser "labadmin" -Properties manager | Select -ExpandProperty Manager
foreach ($group in $ManagedObjects)
{
    Set-ADGroup -Identity $group -ManagedBy $Manager
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM