stess
stess

Reputation: 55

Powershell - concatenate output to csv file

First of all this is my first post, so if there is something I should know about the procedure on Stackoverflow please let me know.

Now, let's get to my problem with powershell. I am creating a powershell script that will retrieve SAMaccountname and ipphone attribute, then export them to csv file.

Import-Module activedirectory

Get-Aduser -filter {ipphone -like "*"} -properties samaccountname,ipphone | select name,samaccountname,ipphone | export-csv "C:\output.csv" -NoTypeInformation

The result is:

namme,samaccount,ipphone

Now... I need a column with domain/samaccountname format instead of standalone samaccountname. What can I do to achieve this?

Upvotes: 2

Views: 1452

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174475

Add a calculated property to the property list when using select:

... | select name,samaccountname,ipphone,@{Label='Username';Expression={"DOMAINNAME\$($_.SamAccountName)"}}

Upvotes: 3

Related Questions