Hi all,
I’m using this script to copy groups from one use to another:
$SourceUser = $null
$Message = "Copy Groups From"
While (!$SourceUser) {
$copyfrom = Read-Host -Prompt $Message
Try {
$SourceUser = Get-ADUser -Identity $copyfrom -Properties memberof -ErrorAction Stop
} Catch {
[void][System.Windows.Forms.MessageBox]::Show(($Message = "User not found. Please enter a user to copy groups from"))
}
}
$SelectedGroups = $SourceUser.memberof | Add-ADGroupMember -Members $username -PassThru | Select-Object -ExpandProperty Name
$Grouptype = $SourceUser.memberof | Add-ADGroupMember -Members $username -PassThru | Select-Object -ExpandProperty GroupCategory
The result that I’m getting is like this
but i want to make 2 rows one with group that copied DL
and one with groups that copied security groups
any idea how can I do it?
Thank you
Olaf
April 8, 2022, 10:37pm
2
Assumed you defined the variable $username
before you run the code you shared here this should be enough to transfer the groups and show what you want after your while loop ran:
$Result = $SourceUser.memberof | Add-ADGroupMember -Members $username -PassThru
$Result | Select-Object -Property Name,GroupCategory
Hi Olaf,
Hope you doing well what I want to show is something like this
DL groups:All-company, all-it
Security groups: admin,domain admin
can it be done?
Olaf
April 9, 2022, 8:22am
4
Did you try my code suggestion? Did it work? What was the output?
I tried what i add to the script
I showed the result in the pic
Olaf
April 9, 2022, 10:11am
6
OK, so why don’t you try my code suggestion?
1 Like
i tried your suggestion but i don’t see this result
im using this code to get the resoult
$subject = "New Users Created"
$Message =
"User Created:
First Name: $firstname
Last Name: $lastname
Employess number: $newNum
Username: $username
E-mail: $email
Sip: $SFB
Groups: $($SelectedGroups -join ",")
Initial Password: $password
Olaf
April 9, 2022, 4:14pm
8
Sorry if that sounds rude but I’d recommend to start reading and answering questions carefully.
My questions were:
The code you posted last has neither to do with any of your code you posted earlier nor mine.
1 Like
Olaf
April 9, 2022, 6:09pm
10
alexxx55555:
this is the output
Now you are playing dumb. Of course I was talking about the output my code suggestion produces.
Regardless of that - the output you produce with a graphical popup or with Write-Host
for example is absolutely useless for everything else than the persons eyes running the code. A more professional attempt would be to output it as CSV or any other reusable data structure.
so your code is not doing what I wanted i will find another solution
I want this pop up for me
Olaf
April 9, 2022, 6:32pm
12
I did not claim that this is the final solution. We try to provide help to help yourself.
1 Like
any other idie from your side?
Olaf
April 9, 2022, 6:49pm
14
I will ask this only once more. What’s the output?
mawazo
April 9, 2022, 8:41pm
15
assuming you want dl groups and security groups in the message box. Use olaf’s solution to split the groupcategory maybe with where object?
$Result = $SourceUser.memberof | Add-ADGroupMember -Members $username -PassThru
$Message =
@"
User Created:
First Name: $firstname
Last Name: $lastname
Employess number: $newNum
Username: $username
E-mail: $email
Sip: $SFB
DL Groups: $($Result.Where({$_.groupcategory -eq 'distribution'}).name -join ',')
Security Groups: $($Result.Where({$_.groupcategory -eq 'security'}).name-join ',')
Initial Password: $password
Makesure to save the intial password in a safe location!
"@
[System.Windows.forms.messagebox]::Show($Message)