none
get users from txt and import them to group RRS feed

  • Question

  • Hi,

    i have user group to which i need to add users.I receive these users either in csv or in txt.

    If the users are on same domain i can add them without any issues, but when they are on different one it gives me issues

    i have t put in credentials otherwise it will tell me that i am not authorized to add users.

    If i put in only one user into $ADusers it will insert user into group. But it does not know what to do with the external file

    $trn = 
    $DEVQA = 
    $PREPROD = 
    $PROD = 
    $DEVTRN = 
    $PHX = 
    $PRG = 
    $KUL = 
    
    #$export = Get-Content "C:\path\export.txt"
    
    #$users = Import-Csv "C:\tmp\scriptsActual\aduser - Copy.csv"
    $ADusers = Get-Content "C:\path\users.txt"
    #$users = $ADusers
    #Get-Content "C:\tmp\scriptsActual\aduser.txt"
    
    $us = "domain\username"
    $pw = Get-Content C:\tmp\securestring.txt | convertto-securestring
    $os = new-object System.Management.Automation.PSCredential ($us, $pw)
    $userDomain = Get-ADUser $ADusers -server $PRG #$._samACcountName #$export.DistinguishedName  #-server $PRG  >> $export      #$ADusers.SamAccountName -server $PRG
    Add-ADGroupMember -Identity $trn -Members $userDomain -Credential $os



    • Moved by Bill_Stewart Monday, April 30, 2018 9:25 PM Unanswerable drive-by question
    Thursday, February 22, 2018 12:35 PM

All replies

  • What is that file supposed to be?  It is not a list of users.

    You cannot create more than one user at a time.  You must use a loop.

    Look in the Gallery for scripts that do what you are asking.

     


    \_(ツ)_/

    Thursday, February 22, 2018 5:34 PM
  • you mean "C:\path\users.txt" has users from multiple domains. 

    Is this credential variable $os specific each OS? in that case I recommend to use "CSV" file with additional column 'domain'. You can use if look to filter out users from each domain from this column and use different credentials for each domain.


    Regards, Vipin Vasudevan

    Thursday, February 22, 2018 5:57 PM
  • I have no idea what is in you file.  If the file has more than one line then it cannot be used without a loop.

    credentials will absolutely have to be for a Domain Admin. THat would be the same for the whole domain.

    I recommend against using the "-Server" when creating users.

    Each user can be returned using "-PassThru" and added t a collection which can be added to the group as a collection.

    I recommend that, before using AD with PowerShell, you study the AD CmdLets and PowerShell basics.

    You can also find many scripts in the Gallery that do this correctly.


    \_(ツ)_/

    Thursday, February 22, 2018 6:07 PM
  • HI,

    I receive list of users in .txt file. these users are from different domains, and i need to add them to group that grant access.

    but when i try to run it i receive

    Get-ADUser : Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADUser' required by parameter 'Identity'. Specified method is not supported.

    and it points to the

    $ADusers = Get-Content "C:\path\users.txt"

    Friday, February 23, 2018 3:08 PM
  • You can only send one user name at a time to Get-AdUser.

    You can do this if the names are SamAccountName, DN, GUID, SID or other identifier.

    Get-Content C:\path\users.txt | Get-AdUser

    If the users are from different domains you will have to know which domains they are from and it will have to be in the file.  Thisis best done by palcing the DistinguishedName in the file.


    \_(ツ)_/

    Friday, February 23, 2018 3:48 PM