Remove Headers

Get-ADUser -Filter *|select GivenName,Name,Enabled,SID | out-file MyDCs.txt

I get an extract like this.

GivenName Name Enabled SID


EFGHIJ ABCDEF… False Z-0-0-00-00000000000-111111…
EFGHIJ ABCDEF… False Z-0-0-00-00000000000-111111…
EFGHIJ ABCDEF… False Z-0-0-00-00000000000-111111…
EFGHIJ ABCDEF… False Z-0-0-00-00000000000-111111…

How can I have only data in the MyDCs.txt file in tab delimited format without the headers

EFGHIJ ABCDEF… False Z-0-0-00-00000000000-111111…
EFGHIJ ABCDEF… False Z-0-0-00-00000000000-111111…
EFGHIJ ABCDEF… False Z-0-0-00-00000000000-111111…
EFGHIJ ABCDEF… False Z-0-0-00-00000000000-111111…

Output does not look good(format), but this will give you what you desire:

Get-ADUser -Filter *|%{ "{0,-10}{1,-10}{2,-60}" -f $_.GivenName,$_.Name,$_.Enabled,$_.SID} | out-file MyDCs.txt

Why don’t you use export-csv instead?

Why without headers?

Get-ADUser -Filter * |
Select-Object -Property GivenName,Name,Enabled,SID |
ConvertTo-Csv -Delimiter “`t” -NoTypeInformation |
Select-Object -Skip 1 |
out-file MyDCs.txt

Just a hint: When you limit your AD query with a -Searchbase it will be faster and less effort for the DC. :wink:

Coz I need to import into a table.

Hmmm … OK.

It does not give out the SID’s and it is not in tab delimited format

FYI:I went for pipe instead.
But how do I get rid of the “” around the data.

But how do I get rid of the "" around the data.
Hmmm ... usually you don't need if you do it right. And you don't need to remove the header as well. Powershell is able to deal with both, headers and quotes, accordingly. What would you like to do with the data? To what kind of table would you like to import them?
Get-ADUser ...|select GivenName,Name,Enabled,SID|%{ "{0}`t{1}`t{2}`t{3}" -f $_.GivenName,$_.Name,$_.Enabled,$_.SID}

There are probably better ways to do whatever you are doing, but this gives you tab delimited output without quotes. If you are looking for a fixed length solution, see Amit’s post above and take a look at string formatting help to understand what it is doing. Here’s a sample.

https://ss64.com/ps/syntax-f-operator.html

Import it into a SQL table.

Can you please tell me other ways of doing this.

You might show a little bit of the code you’re using. There might be other problems with it. Sometimes you try to solve an issue on the left hand side but actually it is on the right hand side … you know what I mean!? :wink:

You mentioned needing to update a table, but without more info, it’s hard to suggest a better solution. Is it a spreadsheet? Database table/what type? You are asking for the data in an odd format that shouldn’t be required in most cases. If the format required is application specific, then there might not be a better way, but we can’t suggest one without knowing more.

Look at Amit’s post, there was a small error where he left one variable/placeholder out in the format string. You need four columns and the command only had 3 listed.

try the following:

get-aduser -Filter * |%{ "{0,-10}{1,-10}{2,-6}{3,-60}" -f $_.GivenName,$_.Name,$_.Enabled,$_.SID}

That should produce the output in a fixed width format which you can pipe to Out-File.

This is the output I produced on my small test:

John      MyUserID   True  S-1-.-................

Good Luck
For Tab Delimited use:

get-aduser -Filter * |%{ "{0}`t{1}`t{2}`t{3}" -f $_.GivenName,$_.Name,$_.Enabled,$_.SID}

the above just adds the tab character (`t) into the format which you can pipe to Out-File or Export-CSV.

Read about the -f operator here:
https://blogs.technet.microsoft.com/pstips/2014/10/18/powershells-format-operator/

Maybe this is the one you are looking for:

Get-ADUser -Filter *|%{ "{0,-25}{1,-25}{2,-10}{3,-60}" -f $_.GivenName,$_.Name,$_.Enabled,$_.SID} | out-file abc.txt

Good Luck!