I just getting into writing Powershell scripts to perform repetitive tasks. I want to write a script that will prompt for an ADgroup, and an AD userID, then add that user to the security group.
It starts like this:
$SecurityGroup = Read-Host -Prompt 'Input the SecurityGroup name'
$User = Read-Host -Prompt 'Input the userID'
Get-ADGroup '$SecurityGroup' | Add-ADGroupMember -Members '$User'
(GET-ADUSER –Identity '$user' –Properties MemberOf | Select-Object MemberOf).MemberOf
Write-Host 'The user with userID '$user' has been added to the SecurityGroup '$SecurityGroup'
Replace the single quotes surrounding your variables with double quotes " or remove the quotes completely. The quotes are not necessary for your usage.
Line
should look something like this (with double quotes surrounding)
About Quoting Rules