Exporting info from PS script to csv

Posted by George on Stack Overflow See other posts from Stack Overflow or by George
Published on 2010-03-18T10:47:50Z Indexed on 2010/03/18 10:51 UTC
Read the original article Hit count: 374

Filed under:
|
|
|
|

Hi,

This is a powershell/AD/Exchange question....

I'm running a script against a number of Users to check some of their attributes however I'm having trouble getting this to output to CSV. The script runs well and does exactly what I need it to do, the output on screen is fine, I'm just having trouble getting it to directly export to csv.

The input is a comma seperated txt file of usernames (eg "username1,username2,username3")

I've experimented with creating custom ps objects, adding to them and then exporting those but its not working....

Any suggestions gratefully received..

Thanks

George

$array = Get-Content $InputPath

#split the comma delimited string into an array
$arrayb = $array.Split(",");

foreach ($User in $arrayb)
{
    #find group memebership
    Write-Host "AD group membership for $User"
    Get-QADMemberOf $User

    #Get Mailbox Info
    Write-Host "Mailbox info for $User"
    Get-Mailbox $User | select ServerName, Database, EmailAddresses, PrimarySmtpAddress, WindowsEmailAddress

    #get profile details
    Write-Host "Home drive info for $User"
    Get-QADUser $User| select HomeDirectory,HomeDrive

    #add space between users
    Write-Host ""
    Write-Host "******************************************************"


}

Write-Host "End Script"

© Stack Overflow or respective owner

Related posts about powershell

Related posts about csv