[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Modify my powershell script

Posted on 2011-02-24
9
Medium Priority
?
687 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
Q2 2017 - Latest Malware & Internet Attacks

WatchGuard’s Threat Lab is a group of dedicated threat researchers committed to helping you stay ahead of the bad guys by providing in-depth analysis of the top security threats to your network.  Check out our latest Quarterly Internet Security Report!

 
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 brief introduction to what I consider to be the best editor for PowerShell.
There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
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…

656 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