Change Powershell script get stats to get user from csv

Dear experts

who can help me with this one below? The input also should come from a csv with 1 column called "user"
with alias or samAccountNamenot no for user at all

Thanks
Mandy

#############################################################################
 # PS-Merge.ps1
 # Description:
 # This script combines three commands and sends the output into a CSV file
 #
 # Jonas Andersson, MCC 2011
 # http://www.testlabs.se/blog
 # Twitter @jonand82
 #############################################################################
 
$Database = @{Name="Database";Expression={ $stats.database }}
 $DisplayName = @{Name="DisplayName";Expression={ $stats.DisplayName }}
 $StorageLimitStatus = @{Name="StorageLimitStatus";Expression={ $stats.StorageLimitStatus }}
 $TotalItemSize = @{Name="MailboxSize";Expression={ $stats.TotalItemSize }}
 $itemcount = @{Name="MailboxSize";Expression={ $stats.itemcount }}
 $Company = @{Name="Company";Expression={ $user.Company}}
 $FirstName = @{Name="FirstName";Expression={ $user.FirstName}}
 $LastName = @{Name="LastName";Expression={ $user.LastName}}
 $LastLogon = @{Name="LastLogon";Expression={ $stats.LastLoggedOnUserAccount}}
 $LastLogonTime = @{Name="LastLogonTime";Expression={ $stats.LastLogonTime}}
 $UserUPN  = @{Name="UPN";Expression={$user.UserPrincipalName}}
 $Primary = @{Name="PrimarySMTP";Expression={$EmailAddress.PrimarySMTPAddress}}
 $Emails   = @{Name="Emails";Expression = { $EmailAddress.EmailAddresses | where { $_.prefixstring -ceq "smtp"}}}
 
 
$Mailboxes = Get-Mailbox -ResultSize Unlimited
 $Mailboxes | foreach {
 $user = Get-User $_
 $stats = Get-MailboxStatistics $_
 $EmailAddress = Get-Mailbox $_
 $_ | select Alias,$DisplayName,$itemcount,$TotalItemSize,$Database,$UserUPN,$Primary,$Emails
 } | Export-CSV -NoTypeInformation C:\AllMailboxesStats.csv

Open in new window

LVL 2
Mandy_Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sirbountyCommented:
Try this:

function Get-UserMailDetails {
  $Inputfile = Get-Content c:\filepath\input.csv
  foreach ($item in $inputfile) {
          if ($item -ne $null) {
		$user = get-user $item
		$mailbox = get-mailbox $user 
		$stats = get-mailboxstatistics $user
		$addr = $mailbox.EmailAddresses | where-object {$_.prefixstring -ceq 'smtp'}
		$obj = new-object psobject
		$obj | add-member noteproperty -name Alias $mailbox.alias
		$obj | add-member noteproperty -name DisplayName -value $stats.DisplayName
		$obj | add-member noteproperty -name Database -value $stats.database
		$obj | add-member noteproperty -name StorageLimitStatus -value $stats.TotalItemSize
		$obj | add-member noteproperty -name ItemCount -value $stats.itemcount
		$obj | add-member noteproperty -name Company -value $user.Company
		$obj | add-member noteproperty -name FirstName -value $user.FirstName
		$obj | add-member noteproperty -name LastName -value $user.LastName
		$obj | add-member noteproperty -name LastLogon -value $stats.lastloggedonuseraccount
		$obj | add-member noteproperty -name LastLogonTime -value $stats.lastlogontime
		$obj | add-member noteproperty -name UserUPN -value $user.userprincipalname
		$obj | add-member noteproperty -name Primary -value $mailbox.primarysmtpaddress
		$obj | add-member noteproperty -name Emails -value $addr
		write-output $obj
	  }
  }	
}

Get-UserMailDetails | Export-CSV -NoTypeInformation C:\filepath\AllMailboxesStats.csv

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mandy_Author Commented:
hi,

thats nice so far.  How should i create the input.csv?  Just Header "User"
0
sirbountyCommented:
How should i create the input.csv?  Just Header "User"
From your requirements:
The input also should come from a csv with 1 column called "user"
I assumed you already had such a file?  I don't believe you need a header line though.
0
Mandy_Author Commented:
verynice! Thank you
0
sirbountyCommented:
Glad I could help - thanks for the grade :^)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.