<# .SYNOPSIS Imports AD module and adds objects specified from a prompt to a Security Group. .DESCRIPTION Adds objects specified by the user in AD to a security group specified by user. .NOTES Version : 1.0 Changes : systems procedures : Active Directory Rights Required : Access to : Active Directory Sched Task Req'd : No Author : Jeff Stein Year Written : 2017 Disclaimer : Resources used : : https://technet.microsoft.com/en-us/library/cc732952(v=ws.11).aspx .EXAMPLE .\Add-MachinetoGroup.ps1 .INPUTS None. You cannot pipe objects to this script. #> Import-Module ActiveDirectory #Loads Active Directory module into powershell script # Asks user to enter the name of the DL or Security Group they wish to add objects to do {$groupname= read-host "Please enter the Active Directory security group you wish to add objects to: "} until (dsquery group -samid $groupname) "" # Asks user to enter the name of the object they wish to add to the group specified do {$computername= read-host "Please enter the Active Directory machine object you wish to add to a security group: "} until (dsquery computer -samid $computername) "" #Get the date that the script is being run $Date= Get-Date Write-host "You input $groupname and $computername on $Date" "" Read-host "Press any key to continue or 'ctrl' c to cancel" "" # Adds the object to the group Add-ADGroupMember -Identity $groupname -Members $computername #Queries the members in the group now $revisedgroup = Get-ADGroupMember -Identity $groupname | select -Property SamAccountName #Validates the object was added to the group if ($revisedgroup -match $computername) {write-host "Machine was added to group."} Else {write-host "Machine not found in group: "$revisedgroup}