Get-ADUser output format

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Sam Boutros Sam Boutros 2 years, 4 months ago.

  • Author
    Posts
  • #17326
    Profile photo of rambog cnonline.net
    rambog cnonline.net
    Participant

    Upon executing "get-aduser -filter * -Server DCName|select sAMAccountName|out-file pathandtextfilename", I get a text file that is double-spaced. How do I prevent this or modify it so that it is single spaced?

    The reason I need to do this is that I need to create an ArrayList [System.Collections.ArrayList] from this text file. Using the Remove method, I plan on taking away users from this ArrayList. The ones being removed are those contained in another text representing inactive users (generated by "Search-ADAccount -AccountInactive -UsersOnly -Timespan "120"|Export-CSV pathandname". I then take the CSV and cut-and-past from the sAMAccountName column to create a text file (for input into an array) representing the inactive users. I then execute the following to remove all the inactive users from the active users list:

    foreach ($item in $inactiveusers) {
    $activeusers.Remove($item) }

    I am doing what is rather circuitous way of getting what are the active users but it seems that Search-ADAccount and Get-ADUser do not yield the information I am looking for. I was thinking of using the directorysearcher next to filter out users based upon lastlogontimestamp (which is a property that seems absent from Search-ADAccount or get-aduser). Beside helping me with removing the double spaces called for above, any other ideas as to improve my approach would be most welcome. Thanks in advance.

  • #17327
    Profile photo of rambog cnonline.net
    rambog cnonline.net
    Participant

    One possible workaround is to do what I did with Search-ADAccount by exporting to CSV. I could export the get-aduser to CSV and then cutandpaste the samaccountname column to create my clean text file for input into the arraylist. Again, any other guidance would be helpful.

  • #17328
    Profile photo of Sam Boutros
    Sam Boutros
    Participant

    XML is more suited to saving and handling complex data types.
    Try using Export-Clixml instead of Out-File at the end of the pipeline.
    It should be much easier to save and retrieve objects as opposed to plain text or CSV files..

    Hope that helps

You must be logged in to reply to this topic.