Answer the question
In order to leave comments, you need to log in
Powershell script how to set a condition?
Good afternoon. There is a script in which there is an addition of groups from a csv file
foreach($group in $Groups)
{
$create_group = New-ADGroup -Name $group.GroupName -groupScope $group.GroupScope -Path $group.ou
}
foreach($line in $UserGroup)
{
$userGroup=$line.ADUsers -split ";"
$groupsList = $line.ADGroup
foreach($user in $line)
{
Add-ADGroupMember -Identity $groupsList -Members $userGroup
}
}
Answer the question
In order to leave comments, you need to log in
1. Google "powershell if group exists".
2. Google "powershell how to add user to group" and "powershell change primary group".
Try like this:
How to write a condition for checking existing groups?
If (Get-AdGroup MyGroup) {Write-Host "Ok"} else {Write-Host "Not Ok"}
1. Do you need it at all? well, there is already such a group, well, it will give an error ... what will change for the result?
2.
Set-ADUser -Replace @{primaryGroupID = $primaryGroupToken}
, where $primaryGroupToken is the corresponding attribute of the desired group.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question