Solved

powershell combine two commands one output

Posted on 2014-09-09
5
637 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

This article explains in simple steps how to renew expiring Exchange Server Internal Transport Certificate.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we show how to create a User Mailbox 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 >> Mailb…
In this video we show how to create a mailbox database 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 >> Data…

856 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