Solved

powershell combine two commands one output

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

We are happy to announce a brand new addition to our line of acclaimed email signature management products – CodeTwo Email Signatures for Office 365.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
To show how to create a transport rule 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 >> Rules tab.:  To cr…
This video discusses moving either the default database or any database to a new volume.

757 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

20 Experts available now in Live!

Get 1:1 Help Now