Mark Minasi's Tech Forum
Sign up Calendar Latest Topics
 
 
 


Reply
  Author   Comment  
meloao

Senior Member
Registered:
Posts: 109
Reply with quote  #1 
Hi,

I have a csv file, $logFile, in the following format:

DATE|EMPID|USERNAME
2020-05-11|12345|jane.johnson
2020-05-11|23456|john.smith
.
.
.
.

I am trying to get all usernames  (ie all the names in column 3 including the header)
0
cj_berlin

Avatar / Picture

Senior Member
Registered:
Posts: 421
Reply with quote  #2 
This

Import-CSV C:\temp\users.txt -Delimiter "|" | Select-Object -Property USERNAME

will get you an array of objects having only one property, USERNAME.

If you need a textfile starting with "USERNAME" you could do an Export-CSV on that even if a CSV with only one column is not something I would like to become known doing [wink]

Or you just dump those usernames and add the column head if you need it

Import-CSV C:\temp\users.txt -Delimiter "|" | Select-Object -ExpandProperty USERNAME | Set-Content c:\temp\usernames.txt



__________________
Evgenij Smirnov

My personal blog (German): http://www.it-pro-berlin.de/
My stuff on PSGallery: https://www.powershellgallery.com/profiles/it-pro-berlin.de/
0
meloao

Senior Member
Registered:
Posts: 109
Reply with quote  #3 
Awesome! Works like a charm!


Can't believe it is only a one-liner! 😉 I was making it more complex then necessary.  I had been trying a foreach loop.


Thanks again as always!
0
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Easily create a Forum Website with Website Toolbox.