[HELP] Export-Csv : Cannot bind argument to parameter InputObject

Welcome Forums General PowerShell Q&A [HELP] Export-Csv : Cannot bind argument to parameter InputObject

  • This topic has 5 replies, 4 voices, and was last updated 1 month ago by
    Participant
    .
Viewing 5 reply threads
  • Author
    Posts
    • #245436
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      I don’t know what happened with my previous post. I did edit it and all of a sudden it’s gone.

      The script is running and the export to csv is correct. But I would like to polish it up without an error.

      I am getting the following error when I run the PS script:

      Param( [string]$MailboxId = '*', [string]$CsvFileName = 'MailboxPermissions.csv' ) $ScriptDir = Split-Path -Path $script:MyInvocation.MyCommand.Path $ScriptName = $MyInvocation.MyCommand.Name # build CSV full path to store CSV in script directory $OutputFile = Join-Path -Path $ScriptDir -ChildPath $CsvFileName Write-Verbose -Message $OutputFile # Fetch mailboxes of type UserMailbox only $Mailboxes = Get-Mailbox -RecipientTypeDetails 'UserMailbox' -Identity $MailboxId -ResultSize Unlimited | Sort-Object $result = @() # counter for progress bar $MailboxCount = ($Mailboxes | Measure-Object).Count $count = 1 ForEach ($Mailbox in $Mailboxes) { $Alias = '' + $Mailbox.Alias # Use Alias property instead of name to ensure 'uniqueness' passed on to Get-MailboxFolderStatistics $DisplayName = ('{0} ({1})' -f $Mailbox.DisplayName, $Mailbox.Name) $activity = ('Working... [{0}/{1}]' -f $count, $mailboxCount) $status = ('Getting folders for mailbox: {0}' -f $DisplayName) Write-Progress -Status $status -Activity $activity -PercentComplete (($count/$MailboxCount)*100) # Fetch folders $Folders = Get-MailboxFolderStatistics $Alias | ForEach-Object {$_.folderpath} | ForEach-Object{$_.replace('/','\')} ForEach ($Folder in $Folders) { # build folder key to fetch mailbox folder permissions $FolderKey = $Alias + ':' + $Folder # fetch mailbox folder permissions $Permissions = Get-MailboxFolderPermission -Identity $FolderKey -ErrorAction SilentlyContinue # store results in variable $result += $Permissions | Where-Object {$_.User -notlike 'Default' -and $_.User -notlike 'Anonymous' -and $_.AccessRights -notlike 'None' -and $_.AccessRights -notlike 'Owner' } | Select-Object -Property @{name='Mailbox';expression={$DisplayName}}, FolderName, @{name='User';expression={$_.User -join ','}}, @{name='AccessRights';expression={$_.AccessRights -join ','}} } # Increment counter $count++ } # Export to CSV $result | Export-Csv -Path $OutputFile -NoTypeInformation -Encoding UTF8 -Delimiter ';' -Force[/crayon]
    • #245385
      Participant
      Topics: 15
      Replies: 1776
      Points: 3,218
      Helping Hand
      Rank: Community Hero

      sindbad97, welcome to Powershell.org. Please take a moment and read the very first post on top of the list of this forum: Read Me Before Posting! You’ll be Glad You Did!.

      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      The line is question appears to be here:

      If the $result variable is null, then you could get an error like you posted. Basically, you should be checking to see if there is anything in $result before you attempt an export, something like this:

    • #245439
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

      @Rob Simmers I tried your edit, but that didn’t work. I am still getting the error.

    • #245730
      Senior Moderator
      Topics: 10
      Replies: 168
      Points: 899
      Helping Hand
      Rank: Major Contributor

      I don’t know what happened with my previous post. I did edit it and all of a sudden it’s gone.

      The edit was caught by the auto-moderator system and marked as spam. If your topic disappears please don’t submit it again. Give the moderators a chance to deal with it. Submitting your topic multiple times creates a mess that we have to clean up.

    • #251534
      Participant
      Topics: 1
      Replies: 3
      Points: 25
      Rank: Member

      I have similar issue. When I run the script in debug mode (F8) it works. But when I execute it directly via PS console as completed PS1 it gives me error “Export-Csv : Cannot bind argument to parameter ‘InputObject’ because it is null.”

      # Find all DHCP Server in Domain
      $DhcpServers = Get-DhcpServerInDC
      #
      foreach ($DHCPServer in $DhcpServers.DnsName){
          if (Test-Connection -BufferSize 32 -Count 1 -ComputerName $dhcpserver -Quiet){
              $ErrorActionPreference = "SilentlyContinue"
              $Scopes = Get-DhcpServerv4Scope -ComputerName $DHCPServer
      #For all scopes in the DHCP server, get the scope options and add them to $LIstofSCopesandTheirOptions
              foreach ($Scope in $Scopes){
                  $LIstofSCopesandTheirOptions += Get-DHCPServerv4OptionValue -ComputerName $DHCPServer -ScopeID $Scope.ScopeId | Select-Object @{label="DHCPServer"; Expression= {$DHCPServer}},@{label="ScopeID"; Expression= {$Scope.ScopeId}},@{label="ScopeName"; Expression= {$Scope.Name}},@{Name=Value;Expression={[string]::join(";", ($_.Value))}},*
              }
              $LIstofSCopesandTheirOptions += Get-DHCPServerv4OptionValue -ComputerName $DHCPServer | Select-Object @{label="DHCPServer"; Expression= {$DHCPServer}},@{Name=Value;Expression={[string]::join(";", ($_.Value))}},*
              $ErrorActionPreference = "Continue"
          }
      }
      #Now we have them all, output them
      $LIstofSCopesandTheirOptions | Export-Csv -Path D:\EAADM\atrubajda\DhcpOptionsReport.csv -Force
      #$ListofScopesandTheirOptions | Out-GridView
    • #251555
      Participant
      Topics: 1
      Replies: 3
      Points: 25
      Rank: Member

      I “solved” this issue by switching to PowerShell version 7.1

Viewing 5 reply threads
  • You must be logged in to reply to this topic.