?
Solved

Modify my powershell script

Posted on 2011-02-24
9
Medium Priority
?
690 Views
Last Modified: 2012-05-11
Hi,

I have this Script writed by Akhater an i need to add and export:

Name of Exchange Server of user
Name of storage group
Name of mailbox database


the script is here:

$mbxs = get-mailbox -resultsize unlimited 
$all = @()
$time = 0
$grp1 = get-group VpnUsers


foreach ($mbx in $mbxs){
     
   $pmail = $mbx.PrimarySmtpAddress.Local + "@" + $mbx.PrimarySmtpAddress.Domain
   $mbxstat = Get-MailboxStatistics $mbx

   $out = new-object psobject    
   $out | add-member noteproperty DisplayName $mbx.DisplayName
   $out | add-member noteproperty Email $pmail
   $out | add-member noteproperty OrganizationalUnit $mbx.OrganizationalUnit
   $out | add-member noteproperty TotalItemSize $mbxstat.totalitemsize.Value.ToMB()


   If($mbx.UseDatabaseQuotaDefaults) {
      $mbdb = get-mailboxdatabase $mbx.database

      if($mbdb.IssueWarningQuota.Value){
         $out | add-member noteproperty IssueWarningQuota $mbdb.IssueWarningQuota.Value.ToMB()
      }
      else {
         $out | add-member noteproperty IssueWarningQuota "Unlimited"
      }

      if($mbdb.ProhibitSendQuota.Value){
         $out | add-member noteproperty ProhibitSendQuota $mbdb.ProhibitSendQuota.Value.ToMB()
      }
      else {
         $out | add-member noteproperty ProhibitSendQuota "Unlimited"
     }
 
      if($mbdb.ProhibitSendReceiveQuota.Value){
         $out | add-member noteproperty ProhibitSendReceiveQuota $mbdb.ProhibitSendReceiveQuota.Value.ToMB()
      }
      else {
         $out | add-member noteproperty ProhibitSendReceiveQuota "Unlimited"
      } 
      
   }
   else {

      if($mbx.IssueWarningQuota.Value){
         $out | add-member noteproperty IssueWarningQuota $mbx.IssueWarningQuota.Value.ToMB()
      }
      else {
         $out | add-member noteproperty IssueWarningQuota "Unlimited"
      }

      if($mbx.ProhibitSendQuota.Value){
         $out | add-member noteproperty ProhibitSendQuota $mbx.ProhibitSendQuota.Value.ToMB()
      }
      else {
         $out | add-member noteproperty ProhibitSendQuota "Unlimited"
     }
 
      if($mbx.ProhibitSendReceiveQuota.Value){
         $out | add-member noteproperty ProhibitSendReceiveQuota $mbx.ProhibitSendReceiveQuota.Value.ToMB()
      }
      else {
         $out | add-member noteproperty ProhibitSendReceiveQuota "Unlimited"
      } 
      
   }

   $out | add-member noteproperty lastLogonTime $mbxstat.LastLogonTime
   $out | add-member noteproperty CustomAttribute1 $mbx.CustomAttribute1
   $out | add-member noteproperty CustomAttribute3 $mbx.CustomAttribute3
   $out | add-member noteproperty CustomAttribute4 $mbx.CustomAttribute4


   if($grp1.members -contains $mbx.DistinguishedName) {
      $out | add-member noteproperty Group1 "Yes"
   }
   else {
      $out | add-member noteproperty Group1 "No"
   }

   $all += $out
} 



$all | export-csv c:\out.csv

Open in new window



Thanks for help
0
Comment
Question by:cawasaki
  • 5
  • 4
9 Comments
 
LVL 27

Expert Comment

by:KenMcF
ID: 34969635
You should be able to just add one line to shoe pull the database field like this
$out = new-object psobject      
   $out | add-member noteproperty DisplayName $mbx.DisplayName  
   $out | add-member noteproperty Email $pmail  
   $out | add-member noteproperty OrganizationalUnit $mbx.OrganizationalUnit  
   $out | add-member noteproperty TotalItemSize $mbxstat.totalitemsize.Value.ToMB()  
   $out | add-member noteproperty Database $mbx.Database

Open in new window

0
 

Author Comment

by:cawasaki
ID: 34969720
Hi Ken,

Are you sure, to add this in my csv export:

Name of Exchange Server of user
Name of storage group
Name of mailbox database

i just need to add add-member noteproperty Database $mbx.Database??

thanks
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34969755
that line should give you the server, storage group, and database in this format

SERVERNAME\STORAGEGROUP\DATABASE
0
What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

 
LVL 27

Accepted Solution

by:
KenMcF earned 2000 total points
ID: 34969790
Wait, just tested, this gives a different output than I expected. Try this


add-member noteproperty StorageGroup $mbx.Database.parent.name
add-member noteproperty DatabaseServer $mbx.Database.name

0
 

Author Comment

by:cawasaki
ID: 34969799
for information, i have EXCHANGE 2007 CCR CLUSTER.
0
 

Author Comment

by:cawasaki
ID: 34969906
hi,

i have test  

add-member noteproperty StorageGroup $mbx.Database.parent.name
add-member noteproperty DatabaseServer $mbx.Database.name



this add StorageGroup      and DatabaseServer but not EXCHANGE SERVER.
0
 
LVL 27

Assisted Solution

by:KenMcF
KenMcF earned 2000 total points
ID: 34969969
ok, that may be becuase the names of my databases in my lab. try this

add-member noteproperty Server $mbx.database.parent.parent.parent.name
0
 

Author Comment

by:cawasaki
ID: 34970094
ok work fine when i add thi 3 line:

add-member noteproperty Server $mbx.database.parent.parent.parent.name
add-member noteproperty StorageGroup $mbx.Database.parent.name
add-member noteproperty DatabaseServer $mbx.Database.name

thanks for your help.
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 34970107
your welcome
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question