Why does Export-Csv prompt me for an InputObject

First of all, here's the script I wrote so far:

Get-Mailbox | Select-Object Name, Alias, ServerName
Get-ADUser -Filter {Enabled -eq $false} | FT samAccountName, Surname,     Enabled

Export-Csv c:\UA.csv -Delimiter " " -NoTypeInformation 

The output basically shows 2 rows of results (Name, Alias and ServerName list above and samAccountName, Surname and Enabled list below). However, below the output it asks me for an InputObject, so clearly the Export-Csv didn't work.

cmdlet Export-Csv at command pipeline position 1
Supply values for the following parameters:
InputObject: 

Am I doing something wrong? I'm a beginner in PowerShell and scripting in general. Thanks in advance.

EDIT (Clarification): The output I am aiming for is one clear table in Excel with all the properties (Name, Alias, Enabled etc.) in a list with separate columns. So far with the help below I have managed to get half of it working.


Solution 1:

I am not 100% sure what you are trying to do, however bassicly the command Export-CSV does not have anything to export for you. This is how it could work:

Get-Mailbox | Select-Object Name,Alias,Servername | Export-csv Filepath\filename.csv -NoTypeInformation
Get-AdUser -Filter {Enabled -eq $false} | Select-Object samAccountName,Surname| Export-csv Filepath\filename.csv -NoTypeInformation

Or

$mailboxes = Get-Mailbox | Select-Object Name,Alias,Servername 
$Users = Get-AdUser -Filter {Enabled -eq $false} | Select-Object samAccountName,Surname

$mailboxes | Export-csv Filepath\filename.csv  -NoTypeInformation
$users | Export-csv Filepath\filename.csv -NoTypeInformation

This way you bassicly pass the results from the commands to the Export csv command. FYI you can use "epcsv" instead of Export-CSV its a short command for it. FYI2 When using this way you cannot use ft (Format-Table) when you do that you get gibberish in your export, this is the same when using fl (Format-List). thus i changed it to Select-Object

If this was not exactly what you were looking for please make your question clearer :)