locked
Powershell AD Users, groups and CSV RRS feed

  • Question

  • Hi All, 

    I`m trying to create a script that will prompt for username, template and depending on the input of each it will add the user to specific security groups and distribution groups from the CSV. I have this working to an extent, it will add the user to one group but when I list a second group in the CSV it fails...here`s what I have so fat;

    $user = Read-Host -Prompt "Enter User Name"
    $template = Read-Host -Prompt "Enter Template Name"
    $Salesgroups = get-content C:\temp\SalesGroup.csv
    $FinanceGroups = get-content C:\temp\FinanceGroup.csv

        If ($Template -eq "Sales")
        {Add-ADGroupMember -Identity $Salesgroups –Member $user}

        If ($Template -eq "Finance")
        {Add-ADGroupMember -Identity $FinanceGroups –Member $user}

    I`d also like a Write-Host message to confirm if it was successful and if Template isn`t "Sales" for example to move onto the next  "If" check. 

    Any help would be appreciated. 

    Scott.

    Monday, June 20, 2016 2:29 PM

Answers

All replies