From a list of users how to to know if they have mailboxes ?

I have the following code but cannot make it cleaner to output a csv
$users = Import-csv C:\Scripts\Exchange2010\users.csv
$users | ForEach { 	$exist = [bool](Get-mailbox $_.name -erroraction SilentlyContinue);Write-host "$Exist $_.Name"}

Open in new window


Thanks for your help,
namergSystems AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Can you show what exactly the output should look like?
0
namergSystems AdministratorAuthor Commented:
i think I got it, need to append it into a csv.

$users = Import-csv C:\Scripts\Exchange2010\users.csv
foreach ($user in $users) { Get-Mailbox $user.name -erroraction SilentlyContinue }

Open in new window


I think my code will screen all the users that have mailboxes according to the users.csv, right ?

Headers:
Name                      Alias                ServerName       ProhibitSendQuota
----                      -----                ----------       -----------------
0
namergSystems AdministratorAuthor Commented:
I am still stuck...I cannot get the csv correct..
foreach ($user in $users) { $exist = [bool](Get-mailbox $user.name -erroraction SilentlyContinue); $MailboxUser2 += "$Exist"+","+"$User.Name" }
$MailboxUser2 | Export-CSV C:\Scripts\Exchange2010\MailboxYesNo.csv -nti

Open in new window

0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

namergSystems AdministratorAuthor Commented:
Everything gets dumped into one cell in when i open the csv with excel and with notepad is one single line :(
0
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Import-csv C:\Scripts\Exchange2010\users.csv |
  Select Name, @{n='MailboxExists'; e={ [bool] (Get-Mailbox $_.Name -ea SilentlyContinue) }} |
  Export-CSV -NoType C:\Scripts\Exchange2010\MailboxYesNo.csv 

Open in new window

Note: You need full-featured objects for Export-CSV, but have built just a long string. That does not work together. In the worst case you just get the string length exported ;-).

If you build your own output string, you need to add line breaks for each row, of course, and then just dump the variable content into Out-File, Add-Content or Set-Content (or similar cmdlets).
1

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
namergSystems AdministratorAuthor Commented:
Hmmm, wowww
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.