asked on
Import-Module ActiveDirectory
Import-Csv "C:\Users\a.narasimha.s\Desktop\Project folder creation\Adduserstogroup.txt" |
ForEach `
{
$users = @($_.samAccount -split ",")
$group = $_.group
write-output "adding users to group ""$group"""
#$users
$users |
ForEach `
{
try
{
$user = $_
Add-ADGroupMember -Identity $group -Members $user
}
catch
{ Write-Output "$user - $($error[0].exception.message)" }
}
}
ASKER
ASKER
Import-Module ActiveDirectory
Import-Csv "C:\Users\a.narasimha.s\Desktop\Project folder creation\Adduserstogroup.txt" | ForEach-Object {
If ($_.Group) {
$Group = $_.Group
}
$Users = @($_.samAccount -split ",")
Write-Output "Adding users to group '$($Group)'"
ForEach ($User In Users) {
Write-Output " - '$($User)'"
Try {
Add-ADGroupMember -Identity $Group -Members $User -ErrorAction Stop
} Catch {
Write-Output "'$($User) - $($Error[0].Exception.Message)"
}
}
}
ASKER
ASKER
"Group", "Samaccount"
"Group1", "Member1Group1"
"", "Member2Group1"
"", "Member3Group1"
"Group2", "Member1Group2"
"", "Member2Group2"
If so, the script I posted above should be able to do this.ASKER
ASKER
Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.
TRUSTED BY
Open in new window