extract email address from Distinguished Names
The script below searches for mailbox with greater than equal to 2 GB in a specific server. What I want to accomplish is to send an email to the Managers of this mailboxes. Basically all the information I need is already in the $combine variable. How can
i send this information to the managers? Contents of the mail should include the Display Name and the totalitemsize of a mailbox.
==========SCRIPT BEGINS HERE===============
#get mailbox that have higher than 2GB in a particular server
$server="<servername>"
$convertGB=@{Name="TotalSize (GB)";expression={$line.Totalitemsize.value.toGB()}}
$storagegrp=@{Name="StorageGroup Name";expression={$line.storagegroupname}}
$combine=@()
$stats = Get-Exchangeserver $server | Get-MailboxStatistics | Where-Object {$_.Totalitemsize.Value.ToGB() -ge 2} | select-object DisplayName,totalitemsize,LegacyDN,storagegroupname
Foreach ($line in $stats) {
$combine += get-user -identity $line.LegacyDN | select-object DisplayName,$convertGB,$storagegrp,Manager
}
$combine | sort-object -descending "TotalSize (GB)"
PoSH newbie, BaSH Oldie
September 26th, 2012 4:39am
Tried adding the line below to query the Manager's information from the $combine by using Get-Mailbox but what is happening is its generating the error below then continue searching for accounts on the whole Exchange server.
If I run Get-Mailbox -identity "<DN>" for one user it works though, only if I use the value in $combine variable then I get the error below and also it search on all the accounts in the server. Which should only be searching from the $combine variable.
ERROR:
Cannot bind argument to parameter 'InputObject' because it is null.
=====BEGIN SCRIPT ===============
Trap {"Error: $_"; Break;}
$server="<servername>"
$convertGB=@{Name="TotalSize (GB)";expression={$line.Totalitemsize.value.toGB()}}
$storagegrp=@{Name="StorageGroup Name";expression={$line.storagegroupname}}
$combine=@()
$mngr=@()
$stats = Get-Exchangeserver $server | Get-MailboxStatistics | Where-Object {$_.Totalitemsize.Value.ToGB() -ge 2} | select-object DisplayName,totalitemsize,LegacyDN,storagegroupname
Foreach ($line in $stats) {
$combine += get-user -identity $line.LegacyDN | select-object DisplayName,$convertGB,$storagegrp,Manager
}
Foreach ($line2 in $combine) {
$mngr += get-mailbox -identity $line2.Manager
}
$mngr
Free Windows Admin Tool Kit Click here and download it now
September 27th, 2012 12:31am
Hi Rich,
Yes this one worked, I was planning to rewrite my script but realising that I have already put so much effort in it. I rather leave it as it is and just put comments in it to help me remind myself.
I'm still learning on posh and ill note what you have advised here.
Thanks a lot!!PoSH newbie, BaSH Oldie
October 16th, 2012 3:14am
On Thu, 27 Sep 2012 04:31:43 +0000, navarro_aries wrote:
>
>
>Tried adding the line below to query the Manager's information from the $combine by using Get-Mailbox but what is happening is its generating the error below then continue searching for accounts on the whole Exchange server.
>
>If I run Get-Mailbox -identity "<DN>" for one user it works though, only if I use the value in $combine variable then I get the error below and also it search on all the accounts in the server. Which should only be searching from the $combine variable.
>
>ERROR: Cannot bind argument to parameter 'InputObject' because it is null.
>
>=====BEGIN SCRIPT ===============
>
>Trap {"Error: $_"; Break;}
>
>$server="<servername>" $convertGB=@{Name="TotalSize (GB)";expression={$line.Totalitemsize.value.toGB()}} $storagegrp=@{Name="StorageGroup Name";expression={$line.storagegroupname}} $combine=@() $mngr=@() $stats = Get-Exchangeserver $server | Get-MailboxStatistics
| Where-Object {$_.Totalitemsize.Value.ToGB() -ge 2} | select-object DisplayName,totalitemsize,LegacyDN,storagegroupname
>
>
>
>Foreach ($line in $stats) { $combine += get-user -identity $line.LegacyDN | select-object DisplayName,$convertGB,$storagegrp,Manager }
>
>Foreach ($line2 in $combine) { $mngr += get-mailbox -identity $line2.Manager }
$line2.Manager is, itself, an object of type
"Microsoft.Exchange.Data.Directory.ADObjectId". If you pipe
$line2.Manager into "gm" you'll see it has it's own set of properties.
Since one of the properties is "name" you don't really need the 2nd
"foreach". Try changing the "select in the 1st "foreach" to this and
see what you get:
....| select DisplayName,...,@{n='Manager',e={$_.Manager.Name}}
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
October 26th, 2012 12:45pm
On Sun, 30 Sep 2012 07:24:05 +0000, navarro_aries wrote:
>This worked in getting the Name of the Manager. However, how is it that getting the e={$_.Manager.Name}} will get the Managers Name and not the users name.
"$_" is the current object (in this case it's the "user"). "Manager"
is the property in the "$_" ofject that is, itself, an object
containing a number of methods and properties. One of the property
names of the object in the "Manager" property is "Name". That "Name"
is the name of the manager.
>From my understanding for get-user the Name attribute is for the name of the user and not of the Managers name, any further clarification on this?
See above. Unlike bash (or any *nix shell) Powershell delivers
"objects" not text as it's result. Even a simple thing like "a" is
represented as an object with methods and properties.
>Also now that I have the Managers Name instead of its DN, how can I obtain the Managers SMTP address? the get-mailbox identity doesnt support display Name instead its the DN.
Try this:
(get-user <your-name>).manager
The "manager" property is an object that also has your manager's
distinguishedname as one of its properties.
So, another 'expression':
@(n='MgrEmail';e={(get-mailbox
($_.manager.distinguishedname)).PrimarySmtpAddress.tostring()}}
If it were me doing this I'd have abandoned the "let's pipe everything
into a long incomprehensible set of nested parentheses and braces"
approch and used simple assignments to get what I needed. When you
look at this stuff six months from now you're going to wonder what the
heck it does!
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
October 26th, 2012 1:55pm
On Wed, 26 Sep 2012 08:39:23 +0000, navarro_aries wrote:
>The script below searches for mailbox with greater than equal to 2 GB in a specific server. What I want to accomplish is to send an email to the Managers of this mailboxes. Basically all the information I need is already in the $combine variable. How
can i send this information to the managers? Contents of the mail should include the Display Name and the totalitemsize of a mailbox.
http://exchangeserverpro.com/powershell-how-to-send-email
If everything you have is in $combine and you want it in HTL then
"$combine | convertto-html" will do it.
You should consider using a search engine to find answers to common
questions.
>==========SCRIPT BEGINS HERE===============
>
>#get mailbox that have higher than 2GB in a particular server
>
>$server="<servername>" $convertGB=@{Name="TotalSize (GB)";expression={$line.Totalitemsize.value.toGB()}} $storagegrp=@{Name="StorageGroup Name";expression={$line.storagegroupname}} $combine=@()
>
>$stats = Get-Exchangeserver $server | Get-MailboxStatistics | Where-Object {$_.Totalitemsize.Value.ToGB() -ge 2} | select-object DisplayName,totalitemsize,LegacyDN,storagegroupname
>
> Foreach ($line in $stats) { $combine += get-user -identity $line.LegacyDN | select-object DisplayName,$convertGB,$storagegrp,Manager }
>
>$combine | sort-object -descending "TotalSize (GB)"
>
>
>PoSH newbie, BaSH Oldie
---
Rich Matheisen
MCSE+I, Exchange MVP
--- Rich Matheisen MCSE+I, Exchange MVP
Free Windows Admin Tool Kit Click here and download it now
October 26th, 2012 7:30pm
Hi Rich,
sorry for the confusion as I can no longer update the subject of my post. its not actually how to send mail in an html format as i have already aware of this.
Basically I already have the information I want in the $combine variable. What I want is to send each Manager with an email advising them about the mailbox sizes. But the Manager is in DN format. I need to search for their email address. And I think another
FOrEach is required to get the value in the $combine variable and locate the Managers email address. How you go about this? I already tried searching the web but cannot find any similarity to it.
PoSH newbie, BaSH Oldie
October 27th, 2012 2:23am
Tried adding the line below to query the Manager's information from the $combine by using Get-Mailbox but what is happening is its generating the error below then continue searching for accounts on the whole Exchange server.
If I run Get-Mailbox -identity "<DN>" for one user it works though, only if I use the value in $combine variable then I get the error. It seems it cannot parse through the values as its not in Quotes.
ERROR:
Cannot bind argument to parameter 'InputObject' because it is null.
=====BEGIN SCRIPT ===============
Trap {"Error: $_"; Break;}
$server="<servername>"
$convertGB=@{Name="TotalSize (GB)";expression={$line.Totalitemsize.value.toGB()}}
$storagegrp=@{Name="StorageGroup Name";expression={$line.storagegroupname}}
$combine=@()
$mngr=@()
$stats = Get-Exchangeserver $server | Get-MailboxStatistics | Where-Object {$_.Totalitemsize.Value.ToGB() -ge 2} | select-object DisplayName,totalitemsize,LegacyDN,storagegroupname
Foreach ($line in $stats) {
$combine += get-user -identity $line.LegacyDN | select-object DisplayName,$convertGB,$storagegrp,Manager
}
Foreach ($line2 in $combine) {
$mngr += get-mailbox -identity $line2.Manager
}
$mngr
Free Windows Admin Tool Kit Click here and download it now
October 27th, 2012 2:39am
Hi RIch,
This worked in getting the Name of the Manager. However, how is it that getting the e={$_.Manager.Name}} will get the Managers Name and not the users name.
From my understanding for get-user the Name attribute is for the name of the user and not of the Managers name, any further clarification on this?
Also now that I have the Managers Name instead of its DN, how can I obtain the Managers SMTP address? the get-mailbox identity doesnt support display Name instead its the DN.
As always, Many Thanks for your assistance
PoSH newbie, BaSH Oldie
October 27th, 2012 5:40am