?
Solved

Modify my powershell script

Posted on 2011-02-24
9
Medium Priority
?
682 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

752 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