?
Solved

powershell combine two commands one output

Posted on 2014-09-09
5
Medium Priority
?
706 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
[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
  • 3
  • 2
5 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 2000 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

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
In this video we show how to create an Accepted Domain 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 Mail Flow >> Ac…
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…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

765 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