locked
get the list of logon script from a csv file RRS feed

  • Question

  • hi,

    i have bulk users 72 , for them i have to get the logon script path , i was working with one script but issue is that its giving me details for one last users put of 72 , if i will remove last 10 users it will give only for 62th user , means last user in sheet , dont know what is wrong .

    Import-Csv "C:\Scripts\csv72.csv" | ForEach-Object {
     $samAccountName = $_."samAccountName"
     $scriptpath = $_."scriptpath"
    Get-ADUser -Identity $samAccountName |
     Get-ADUser –Properties "sAMAccountName","scriptpath" |Select-Object -Property "sAMAccountName", "scriptpath" | export-CSV C:\temp\csv72.csv
    }
    Wednesday, October 25, 2017 8:55 AM

Answers

  • You need to use -Append attribute in the end.

    Export-CSV C:\temp\csv72.csv -Append -NoTypeInformation


    Please click on Propose As Answer or to mark this post as and helpful for other people. This posting is provided AS-IS with no warranties, and confers no rights.

    • Marked as answer by Balal Ahmad Sunday, October 29, 2017 7:35 AM
    Friday, October 27, 2017 9:31 AM

All replies

  • Every time you export you are overwriting the CSV file.  Be  little neater with your code and you will be able to see your errors better.

    Import-Csv C:\Scripts\csv72.csv | 
    	ForEach-Object {
    		Get-ADUser $_.SamAccountName -Properties scriptpath 
    	} |
    	Select-Object sAMAccountName,scriptpath | 
    	Export-CSV C:\temp\csv72.csv


    \_(ツ)_/

    Wednesday, October 25, 2017 9:07 AM
  • can u be kind and correct it i dont have much idea about scripting...
    Wednesday, October 25, 2017 9:23 AM
  • Hi,

    I'm checking how the issue is going, was your issue resolved?

    And if the replies as above are helpful, we would appreciate you to mark them as answers, and if you resolve it using your own solution, please share your experience and solution here. It will be greatly helpful to others who have the same question.

    Appreciate for your feedback.

    Best Regards,
    Albert Ling

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Friday, October 27, 2017 9:14 AM
  • You need to use -Append attribute in the end.

    Export-CSV C:\temp\csv72.csv -Append -NoTypeInformation


    Please click on Propose As Answer or to mark this post as and helpful for other people. This posting is provided AS-IS with no warranties, and confers no rights.

    • Marked as answer by Balal Ahmad Sunday, October 29, 2017 7:35 AM
    Friday, October 27, 2017 9:31 AM
  • Thanks Vlad !!
    Sunday, October 29, 2017 7:35 AM