1

I'm using Powershell to export users to a CSV. Everything works fine but I would like to add commands for Live@edu to each line for import. The text I would like to add is "Add,Mailbox," before each line. Can this be done before the export-csv? Thanks in advance.

Here is the export code:

$CSV = @()
get-qaduser -searchroot 'OU=Test Live,DC=domain,DC=edu' -sizelimit 0 | foreach-object {
    $attributes = get-qaduser $_ | Select-Object Name,Mail,givenName,sn,displayName
    $CSV += $attributes
}
$CSV | export-csv -path "c:\test.csv" -encoding unicode -notypeinformation
2
  • So you want to add two new fields to each row? Or change the contents of the first field in each row? Commented Jul 27, 2011 at 20:30
  • 2 fields would be nice. Sorry but this is my first attempt at Powershell so I'm kind of new. Thanks! Commented Jul 27, 2011 at 21:23

2 Answers 2

2

Try this, it adds two new columns (properties), Action (add) and Resource (mailbox) for each user object:

Get-QADUser -SearchRoot 'OU=Test Live,DC=domain,DC=edu' -SizeLimit 0 | Select-Object @{Name='Action';Expression='Add'}},@{Name='Resource';Expression='Mailbox'}},Name,Email,GivenName,LastName,DisplayName | Export-Csv -Path c:\test.csv -Encoding Unicode -NoTypeInformation
Sign up to request clarification or add additional context in comments.

2 Comments

No dice, but very close. It did add the 2 extra columns for Action and Resource but the fields were empty before each user.
AHAHA!! I see it now! It was simply missing the { token on the left of the expression value! Thanks a million Shay! {'Add'}}and {'Mailbox'}}
1

This should produce tw new fields on the front of each row. Can't test it right now though:

$CSV = @()
get-qaduser -searchroot 'OU=Test Live,DC=domain,DC=edu' -sizelimit 0 | foreach-object {
    $attributes = get-qaduser $_ | Select-Object @{n='Add';e='Add';}, @{n='Mailbox';e='Mailbox'},Name,Mail,givenName,sn,displayName
    $CSV += $attributes
}
$CSV | export-csv -path "c:\test.csv" -encoding unicode -notypeinformation

6 Comments

Any reason | Select-Object Add,Mailbox,Name,Mail,givenName,sn,displayName wouldn't work just a well?
Actually now that you mention it, none that I can think of. Just habit to do it that way.
Thanks for the input guys, but I'm afraid neither worked. The first method using : @{n='Add';e='';}, @{n='Mailbox';e=''}, returned the error Select-Object : Key "expression" cannot have an empty string value. The second method of just using Add,Mailbox, simply put empty fields. I am reading AD attributes so I guess when it went to AD and didn't see an Add or Mailbox attribute it returned null.
So you are saying that your AD objects have a field on them called 'Add'?
No there are no attributes labeled Add or Mailbox. These are just the 2 commands that Live@edu needs when importing a CSV for mailbox creation. For example, if I wanted to delete a mailbox the CSV would need to be formatted: Delete,Mailbox,Name,Mail,givenName, etc.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.