Adding members to Active Directory Login Groups in SQL Server through powershell
By using the below command lets we can add members to the active directory login groups. While Providign Group name dont provide the Domain name group alone works.
<# The below Windows feature command will import Poweshell Module Add-WindowsFeature #> Add-WindowsFeature RSAT-AD-PowerShell Import-Module ServerManager import-module activedirectory <# Space is compulsory between FirstName and LastName else it throws error Depends on requirement you can choose like(-like) or equal(-eq) commands. #> Get-ADUser -Filter 'Name -like "*Ramesh, Mamillapalli"' Add-ADGroupMember -Identity "GroupNameHere" -Members (Get-ADUser -Filter 'Name -like "*Ramesh, Mamillapalli"')
Get-ADUser -Filter 'Name -like "*MamilRam*"'
cls $GroupName='GroupNameHere' Get-ADGroup -filter *|sort name|Where-object {$_.Name -eq $GroupName}|Get-ADGroupMember| Select-Object @{Name="GroupName";Expression={$GroupName}},Name,SamAccountName|Format-Table -AutoSize
#Dont pass domain name like this domainname\groupname cls $GroupNames=@('ADGroup1', 'ADGroup2') $GroupNames| ForEach-Object{ $SingGroup=$_ Get-ADGroup -filter *|sort name|Where-object {$_.Name -eq $SingGroup}|Get-ADGroupMember| Select-Object @{Name="GroupName";Expression={$SingGroup}},Name,SamAccountName|Format-Table -AutoSize }
get-aduser -filter "(GivenName -like 'Ramesh*')-and (Surname -like 'Mamillapalli*')"| Format-Table GivenName,Name,SamAccountName,SurName,UserPrincipalName
Get-Aduser -Filter 'SamAccountName -like "*rama*"' -Properties *|Format-List * *
Comments