combining two cmdlets
Hi Rich, For the line below, this one is working for me, however I want to know why Get-User command supports LEgacyDN when it doesnt have LegacyDN as its attributes? $u = get-user -Identity $line.LegacyDN For the rest of the script you gave me since its failing on my side I modified it instead to look like below. It works if I removed $line.Totalitemsize. Any idea why? ####################### $server="<serverlist.txt>" $combine=@() $stats = Get-Exchangeserver $server | Get-MailboxStatistics | Where-Object {$_.Totalitemsize.Value.ToGB() -ge 2} | select-object DisplayName,totalitemsize,LegacyDN Foreach ($line in $stats) { $combine += get-user -identity $line.LegacyDN | select-object DisplayName,Manager,$line.Totalitemsize } $combinePoSH newbie, BaSH Oldie
October 26th, 2012 7:46am

On Tue, 25 Sep 2012 09:54:11 +0000, navarro_aries wrote: >For the line below, this one is working for me, however I want to know why Get-User command supports LEgacyDN when it doesnt have LegacyDN as its attributes? > >$u = get-user -Identity $line.LegacyDN Don't confuse the underlying LDAP query with the attribues that are present in the object that's created by the cmdlet. >For the rest of the script you gave me since its failing on my side I modified it instead to look like below. It works if I removed $line.Totalitemsize. Any idea why? Because that isn't present in the data being piped to the "select-object". "$line" is a completely different object to the results the "get-user" cmdlet sends into the pipe. >####################### >$server="<serverlist.txt>" >$combine=@() >$stats = Get-Exchangeserver $server | Get-MailboxStatistics | Where-Object {$_.Totalitemsize.Value.ToGB() -ge 2} | select-object DisplayName,totalitemsize,LegacyDN >Foreach ($line in $stats) { $combine += get-user -identity $line.LegacyDN | select-object DisplayName,Manager,$line.Totalitemsize >} >$combine Try replacing the simple "totalitemsize" in your select-object with an expression: select-object DisplayName,Manager,@{n='TotalItemSize';e={$line.totalitemsize}} As I said, sometimes the longer form is easier to understand than the short "one-liners" that many people seem to prefer. Eventually, you'll have a problem with Powershell remoting and its limitations with piping the results of remote execution. --- 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 11:32am

On Mon, 24 Sep 2012 08:03:18 +0000, navarro_aries wrote: > > >I have a script below that should query mailbox that have more than 2GB of size and display the Manager field but its not working. I dont get any error message though. Any ideas? > >$server="<servername>" $combine=@() > >$stats = Get-Exchangeserver $server | Get-MailboxStatistics | Where-Object {$_.Totalitemsize -ge "2147483648"} | select-object DisplayName,totalitemsize > > > >Foreach ($line in $stats) { $combine += get-user | where-object {$_.displayname -eq $line} | select-object displayname, Manager, $line.Totalitemsize } > >$combine | export-csv report.csv $line contains "DisplayName" and "totalitemsize". Comparing the object $line to the user's displayName property won't work. Try "{$_.DisplayName -eq $line.DisplayName}" and see if that works. I think you're also going to have problems becasue for each object in $stats you're going to retreive ALL the uses in the AD and compare them their displayname. It'd make more sense to just get the user you're after, wouldn't it? And, because displaynames aren't guaranteed to be unique (in fact, they many not even be present!) you stand a chance of getting more than a single user ofject. Use the LegacyDN instead. Note that the "TotalItemSize is itself an object! Use it's "Value" property to get a number instead of a string that probably isn't what you want. Oh, and you can convert that value into KB, MB, or GB so you don't have to remember that a GB is 1024*1024*1024 and you want 1024*1024*1024*2. ;-) $server="<servername>" $combine=@() $stats = Get-Exchangeserver -server $server | Get-MailboxStatistics | Where-Object {$_.Totalitemsize.Value.ToGB() -ge 2} | select-object LegacyDN,DisplayName,totalitemsize foreach ($line in $stats) { $u = get-user -Identity $line.LegacyDN $x = "" | DisplayName,Manager,TotalItemSize $x.DisplayName = $u.DisplayName $x.Manager = $u.Manager $x.TotalItemSize = $line.totalitemsize $combine += $x } $combine | export-csv report.csv The "Manager" property is a distinguishedName. If you want the displayName of the manager you'll replace the simple assignment with something like this: if {$u.Manager -is [object]} { $x.Manager = (get-user -identity $u.Manager).displayname } There are probably shorter ways of getting what you're after, but sometimes longer is easier to understand. --- Rich Matheisen MCSE+I, Exchange MVP --- Rich Matheisen MCSE+I, Exchange MVP
October 26th, 2012 5:39pm

I have a script below that should query mailbox that have more than 2GB of size and display the Manager field but its not working. I dont get any error message though. Any ideas? $server="<servername>" $combine=@() $stats = Get-Exchangeserver $server | Get-MailboxStatistics | Where-Object {$_.Totalitemsize -ge "2147483648"} | select-object DisplayName,totalitemsize Foreach ($line in $stats) { $combine += get-user | where-object {$_.displayname -eq $line} | select-object displayname, Manager, $line.Totalitemsize } $combine | export-csv report.csvPoSH newbie, BaSH Oldie
Free Windows Admin Tool Kit Click here and download it now
October 27th, 2012 6:31am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics