【发布时间】:2020-03-31 22:45:21
【问题描述】:
我目前正在测试以下场景,并希望将其自动化定义和验证参数。
我已将以下 cmdlet 放在一起以使脚本能够逐行调用,但我最终喜欢的是查看 CSV 文件中的用户列表。在这个文件中,我想使用带有 UserPrincipalName 标题的两列,例如:
来源用户 |目标用户
这个想法是运行一个脚本并替换以下内容:
#create variables
$sourceUser = "TestUser1@old.domain.com"
$targetUser = "TestUser1@new.domain.com"
$sourceusername,$sourcedomain = $sourceUser -split ("@")
$targetusername,$targetdomain = $targetUser -split ("@")
$SourceAccount = Get-ADUser $sourceusername -server $sourcedomain -Properties objectSid
$TargetAccount = Get-ADUser $targetusername -Server $targetdomain
#get the objectSid of the source account
$objectSid = $SourceAccount.objectSid
#copy source account objectSid to target account msExchMasterAccountSid
$TargetAccount | Set-ADUser -Replace @{"msExchMasterAccountSid"=$objectSid}
#enable target account
$TargetAccount | Enable-ADAccount
#disable the source account
$SourceAccount | Disable-ADAccount
#move the migrated user into prod OU
$TargetAccount | Move-ADObject -TargetPath "OU=Test,OU=Users,DC=new,DC=domain,DC=com"
我已经找到了几个我认为有助于实现目标域和目标 OU 等两件事的参数:
[CmdletBinding()]
Param(
#target domain
[parameter(Mandatory,Position=1)]
[ValidateScript({Get-ADDomain -Identity $_})]
[String]$Domain,
#target OU
[parameter(Position=2)]
[ValidateScript({Get-ADOrganizationalUnit -Identity $_})]
[String]$TargetOu
)
有没有人可以帮我把所有这些脚本放在一起,好吗? ????
谢谢
【问题讨论】:
-
如果您告诉我们您卡在哪里,我们可以在您遇到困难时提供帮助。
-
当然 - 但我也在寻找一些关于开始点的想法。诚然,我会在编写脚本的同时发布我的问题。
标签: powershell csv active-directory