User Tools

Site Tools

#Copy Members from Group 1 to Group 2
function Get-ScriptDirectory
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
$ScriptPath = Get-ScriptDirectory
$group1 = Read-Host "Enter GroupName to copy from"
$group2 = Read-Host "Enter GroupName to copy to"
$membersInGroup1 = Get-ADGroupMember $group1
$membersInGroup2 = Get-ADGroupMember $group2
$membersInGroup1 | % {Add-ADGroupMember -Identity $group2 -Member $_
$LogDate = (Get-Date).ToString("yyyy.MM.dd")
$LogTime = (Get-Date).ToLongTimeString()
$LogPath = Test-Path "$ScriptPath\Logging"
if ($LogPath -eq $True) {"----------------------------------------------------" | Out-File -FilePath "$ScriptPath\Logging\Log_$LogDate.log" -Append}
else {New-Item -Path "$ScriptPath\Logging" -ItemType directory}
"$LogDate $LogTime Done! Account $_ added to Group $group2 or allready present.." | Out-File -FilePath "$ScriptPath\Logging\Log_$LogDate.log" -Append}
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
copy_ad_group_members.txt · Last modified: 2017/06/13 17:23 by