Removing Spaces in a Table

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.

August 25th, 2015 2:39pm

Hi,

Get rid of the Format-

Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 2:43pm

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.

August 25th, 2015 4:06pm

You could always just trim your input in your other sc
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 4:15pm

Try using convertto-csv instead of exporting, then skip the first line and use out-file

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

August 25th, 2015 4:19pm

Silly me, that would be too easy.  Sorry, I didn't think of that.  Thanks.  I got it.
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 4:33pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics