Solved

powershell combine two commands one output

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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
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…
This video demonstrates how to sync Microsoft Exchange Public Folders with smartphones using CodeTwo Exchange Sync and Exchange ActiveSync. To learn more about CodeTwo Exchange Sync and download the free trial, go to: http://www.codetwo.com/excha…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

729 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