Solved

Modify my powershell script

Posted on 2011-02-24
9
644 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
Comment Utility
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
Comment Utility
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
Comment Utility
that line should give you the server, storage group, and database in this format

SERVERNAME\STORAGEGROUP\DATABASE
0
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:cawasaki
Comment Utility
for information, i have EXCHANGE 2007 CCR CLUSTER.
0
 

Author Comment

by:cawasaki
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
your welcome
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
This article will help you understand what HashTables are and how to use them in PowerShell.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now