Posted On October 28, 2021

PowerShell: Add User To Group in Active Directory

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Add User To Group in Active Directory
$userId='kimconnect'
$groupName='Remote Desktop Users'

function addUserToGroup($userId,$groupName){
  $userExists=Get-ADGroupMember $groupName|?{$_.SamAccountName -eq $userId}
  if(!$userExists){
      Add-ADGroupMember -Identity $groupName -Members $userId
  }else{
      write-host "User ID '$userId' already exists in group '$groupName'"
  }
}

addUserToGroup $userId $groupName

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

WinRM and Trusted Hosts for Non-Domain Computers

Error: [TESTWINDOWS] Connecting to remote server TESTWINDOWS failed with the following error message : Access…

Linux: Enable PowerShell Remoting WinRM Client on Ubuntu 20.04

This note is a work-in-progress as the NTLM authentication support module by Microsoft for Ubuntu…

Installing DotNet 3.5 on Windows with Restricted Internet Access

# Set Windows Source files # Assuming that a Windows ISO / DVD Rom have…