Solved

powershell combine two commands one output

Posted on 2014-09-09
5
596 Views
Last Modified: 2014-09-09
I am trying to build this script but getting the following error message and it is processing everything not just the contents in the csv file




WARNING: By default, only the first 1000 items are returned. Use the ResultSize parameter to specify the number of
items returned. To return all items, specify "-ResultSize Unlimited". Be aware that, depending on the actual number of
items, returning all items can take a long time and consume a large amount of memory. Also, we don't recommend storing
the results in a variable. Instead, pipe the results to another task or script to perform batch changes.Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Get-MailboxStatistics], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-MailboxStatistics

$userList = Get-Content c:\listofusers.csv

$masterinfo = @()

foreach ($user in $userList)
      {
      $tempinfo = @()
      $tempinfo = "" | Select displayName, alias, Database,itemcount,RecipientTypeDetails,primarysmtpaddress,  totalitemsize, identity, IssueWarningQuota, ProhibitSendQuota, UseDatabaseQuotaDefaults, SingleItemRecoveryEnabled
      

      $mb = get-mailbox -id $_ | select displayname, alias, database, RecipientTypeDetails, primarysmtpaddress, identity,IssueWarningQuota, ProhibitSendQuota, UseDatabaseQuotaDefaults, SingleItemRecoveryEnabled
      
       $mbxstats = Get-Mailboxstatistics -id $_ | select DisplayName, @{n='Totalitemsize';e={
    If ($_.TotalItemSize.Value.ToBytes() -gt 1GB) {
      "$($_.TotalItemSize.Value.ToGB())GB"
    } ElseIf ($_.TotalItemSize.Value.ToBytes() -gt 1MB) {
      "$($_.TotalItemSize.Value.ToMB())MB"
    } Else {
      "$($_.TotalItemSize.Value.ToKB())KB"
    } }}, ItemCount,StorageLimitStatus
        $fldstats = Get-Mailboxfolderstatistics -id $_ |
    select-object name, @{n='Foldersize';e={
    If ($_.Foldersize.ToBytes() -gt 1GB) {
      "$($_.Foldersize.ToGB())GB"
    } ElseIf ($_.Foldersize.ToBytes() -gt 1MB) {
      "$($_.Foldersize.ToMB())MB"
    } Else {
      "$($_.Foldersize.ToKB())KB"
    } }}

      $tempinfo.DisplayName = $mb.DisplayName
      $tempinfo.alias = $mb.alias
      $tempinfo.RecipientTypeDetails = $mb.RecipientTypeDetails
      $tempinfo.primarysmtpaddress = $mb.primarysmtpaddress
      $tempinfo.identity = $mb.identity
      $tempinfo.IssueWarningQuota = $mb.IssueWarningQuota
      $tempinfo.ProhibitSendQuota = $mb.ProhibitSendQuota
      $tempinfo.SingleItemRecoveryEnabled = $mb.SingleItemRecoveryEnabled
      $tempinfo.alias = $mb.alias
      $tempinfo.database = $mb.database
      $tempinfo.totalitemsize = $mbxstats.totalitemsize
      $tempinfo.itemcount = $mbxstats.itemcount
      
      $masterinfo += $tempinfo
      }

$masterinfo | Select displayName, alias, Database,itemcount,RecipientTypeDetails,primarysmtpaddress,  totalitemsize, identity, IssueWarningQuota, ProhibitSendQuota, UseDatabaseQuotaDefaults, SingleItemRecoveryEnabled | export-csv c:\something.csv
0
Comment
Question by:techdrive
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 40312623
At First look, you need to change the following lines..

Change $_ to $user

$mb = get-mailbox -id $user | select displayname, alias, database, RecipientTypeDetails, primarysmtpaddress, identity,IssueWarningQuota, ProhibitSendQuota, UseDatabaseQuotaDefaults, SingleItemRecoveryEnabled
       
        $mbxstats = Get-Mailboxstatistics -id $user | select DisplayName.............

.........
.........

$fldstats = Get-Mailboxfolderstatistics -id $user |

Open in new window

Also c:\listofusers.csv should be without header..
UserA
UserB
UserC

Open in new window

0
 

Author Comment

by:techdrive
ID: 40312650
thanks it fixed the first issue but still getting


Cannot bind argument to parameter 'Identity' because it is null.
    + CategoryInfo          : InvalidData: (:) [Get-MailboxFolderStatistics], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Get-MailboxFolderStatistics
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40312728
You probably missed the last one..
$fldstats = Get-Mailboxfolderstatistics -id $user |

Open in new window

0
 

Author Comment

by:techdrive
ID: 40313084
Found the issue and thanks again subsun for all your help./
0
 
LVL 40

Expert Comment

by:Subsun
ID: 40313141
You are welcome!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Issue with Outlook Mail 13 58
Calendar and Email kept in Andriod 6 23
Filter IP range with PowerShell 1 30
Move for SBS 2011 to Office 365 3 33
Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
To show how to generate a certificate request in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Servers >> Certificates…

863 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now