none
Removing Spaces in a Table RRS feed

  • Question

  • I have the following script, it's a one liner but still a script, that it's working but giving me undesired spaces.

    Get-ADUser -Server ServerName -Filter * -Properties whenCreated | Where-Object {$_.whenCreated -ge ((Get-Date).AddHours(-24)).Date} |Select-Object Name |Format-Table -HideTableHeaders |Out-File C:\Scripts\NewUserList.txt

    The result would be some like this
    abc123                                            
    xyz321                            
    nmo321                                          

    Noticed that there are a lot of spaces after the user name.  When I feed this file to another script, it fails because it's looking for the username with the spaces in them.

    How can I remove the spaces in my result?

    Thanks.

    Tuesday, August 25, 2015 6:35 PM

Answers

  • You could always just trim your input in your other script then.
    EDIT: Since you're only after a single property, add -ExpandProperty to your Select statement and drop the Format-Table.

    • Edited by Mike Laughlin Tuesday, August 25, 2015 8:25 PM
    • Marked as answer by abdielh Tuesday, August 25, 2015 8:30 PM
    Tuesday, August 25, 2015 8:12 PM

All replies

  • Hi,

    Get rid of the Format-Table.


    EDIT: Also, I recommend using Export-Csv instead of Out-File.

    Tuesday, August 25, 2015 6:39 PM
  • If I get rid of Format-Table, then I get the Headers:
    Name
    ---------

    I don't really want that. I just want a simple list of newly created users in the last 24 hours. I get a similar issue if I use CSV.

    Tuesday, August 25, 2015 8:03 PM
  • You could always just trim your input in your other script then.
    EDIT: Since you're only after a single property, add -ExpandProperty to your Select statement and drop the Format-Table.

    • Edited by Mike Laughlin Tuesday, August 25, 2015 8:25 PM
    • Marked as answer by abdielh Tuesday, August 25, 2015 8:30 PM
    Tuesday, August 25, 2015 8:12 PM
  • Try using convertto-csv instead of exporting, then skip the first line and use out-file

    | ConvertTo-Csv -NoTypeInformation | select -Skip 1 | Out-file ......

    Tuesday, August 25, 2015 8:15 PM
  • Silly me, that would be too easy.  Sorry, I didn't think of that.  Thanks.  I got it.
    Tuesday, August 25, 2015 8:30 PM