S
st0rch
Guest
Hey everyone,
I'm extremely new to coding, and not very good with C# or C++. I've made a powershell script to mirror an active directory user's groups and copy it over to another user, while deleting their old access and am trying to implement it into a GUI in visual studio and have no idea where to begin.
I've designed a simple "enter a name here and a name to copy access to here" gui in VS
So far I've got the script to work, and it even shows a list of groups I'm not able to move because of permissions. From a complete noob, is there any place I can go to learn to integrate this into my GUI that was made in visual studio? All I've done is design it, and have no idea what to do next. Any advice or help that someone could offer would be extremely appreciated. I would like the GUI to simply say if it was successful, and somehow show any groups that were unsuccessfully moved.
Here's my PS script:
# Script to copy group memberships from a source user to a target user.
Param ($Source, $Target)
If ($Source -ne $Null -and $Target -eq $Null)
{
$Target = Read-Host "Enter logon name of target user"
}
If ($Source -eq $Null)
{
$Source = Read-Host "Enter logon name of source user"
$Target = Read-Host "Enter logon name of target user"
}
# Retrieve group memberships.
$SourceUser = Get-ADUser $Source -Properties memberOf
$TargetUser = Get-ADUser $Target -Properties memberOf
# Hash table of source user groups.
$List = @{}
#Enumerate direct group memberships of source user.
ForEach ($SourceDN In $SourceUser.memberOf)
{
# Add this group to hash table.
$List.Add($SourceDN, $True)
# Bind to group object.
$SourceGroup = [ADSI]"LDAP://$SourceDN"
# Check if target user is already a member of this group.
If ($SourceGroup.IsMember("LDAP://" + $TargetUser.distinguishedName) -eq $False)
{
# Add the target user to this group.
Add-ADGroupMember -Identity $SourceDN -Members $Target
}
}
# Enumerate direct group memberships of target user.
ForEach ($TargetDN In $TargetUser.memberOf)
{
# Check if source user is a member of this group.
If ($List.ContainsKey($TargetDN) -eq $False)
{
# Source user not a member of this group.
# Remove target user from this group.
Remove-ADGroupMember $TargetDN $Target
}
}
Continue reading...
I'm extremely new to coding, and not very good with C# or C++. I've made a powershell script to mirror an active directory user's groups and copy it over to another user, while deleting their old access and am trying to implement it into a GUI in visual studio and have no idea where to begin.
I've designed a simple "enter a name here and a name to copy access to here" gui in VS
So far I've got the script to work, and it even shows a list of groups I'm not able to move because of permissions. From a complete noob, is there any place I can go to learn to integrate this into my GUI that was made in visual studio? All I've done is design it, and have no idea what to do next. Any advice or help that someone could offer would be extremely appreciated. I would like the GUI to simply say if it was successful, and somehow show any groups that were unsuccessfully moved.
Here's my PS script:
# Script to copy group memberships from a source user to a target user.
Param ($Source, $Target)
If ($Source -ne $Null -and $Target -eq $Null)
{
$Target = Read-Host "Enter logon name of target user"
}
If ($Source -eq $Null)
{
$Source = Read-Host "Enter logon name of source user"
$Target = Read-Host "Enter logon name of target user"
}
# Retrieve group memberships.
$SourceUser = Get-ADUser $Source -Properties memberOf
$TargetUser = Get-ADUser $Target -Properties memberOf
# Hash table of source user groups.
$List = @{}
#Enumerate direct group memberships of source user.
ForEach ($SourceDN In $SourceUser.memberOf)
{
# Add this group to hash table.
$List.Add($SourceDN, $True)
# Bind to group object.
$SourceGroup = [ADSI]"LDAP://$SourceDN"
# Check if target user is already a member of this group.
If ($SourceGroup.IsMember("LDAP://" + $TargetUser.distinguishedName) -eq $False)
{
# Add the target user to this group.
Add-ADGroupMember -Identity $SourceDN -Members $Target
}
}
# Enumerate direct group memberships of target user.
ForEach ($TargetDN In $TargetUser.memberOf)
{
# Check if source user is a member of this group.
If ($List.ContainsKey($TargetDN) -eq $False)
{
# Source user not a member of this group.
# Remove target user from this group.
Remove-ADGroupMember $TargetDN $Target
}
}
Continue reading...