• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 34
  • Last Modified:

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,
0
namerg
Asked:
namerg
  • 4
  • 2
1 Solution
 
QlemoBatchelor, 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
On-Demand: Securing Your Wi-Fi for Summer Travel

Traveling this summer?Check out our on-demand webinar to learn about the importance of Wi-Fi security and 3 easy measures you can start taking immediately to protect your private data while using public Wi-Fi. Follow us today to learn more!

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

Join & Write a Comment

Featured Post

WEBINAR: 10 Easy Ways to Lose a Password

Join us on June 27th at 8 am PDT to learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees. We'll cover the importance of multi-factor authentication and how these solutions can better protect your business!

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now