Solved

Modify my powershell script

Posted on 2011-02-24
9
668 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Backup Solution for AWS

Read about how CloudBerry Backup fully integrates your backups with Amazon S3 and Amazon Glacier to provide military-grade encryption and dramatically cut storage costs on any platform.

 
LVL 27

Accepted Solution

by:
KenMcF earned 500 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 500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
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…

749 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