I have found the custom lists in a particular site and I want to print the names to Excel. How do I do it?


You can pipe the output from your command to an .csv file:

FileToExecute.ps1 | Out-File C:\output.csv

Make sure you in your script file uses Write-Outputand not Write-Host when printing your output.


Use the following Command:

$spWeb = Get-SPWeb SiteUrl
$spWeb.Lists | select Title | Export-CSV c:\Lists.csv

You can export any output of the powershell to a CSV. This is a built in function.



You wanna use the Export-Csv parameter. I also found this easy example.

SharePoint list to .csv file


$MyWeb = WebUrl 
$MyList = MyWeb.Lists["ListName"] 
$MyItems = $MyList.Items
$MyItems | Select Fields.. | Export-Csv -path C:\example\excel.csv

Using the Export-CSV as usual way we can export the SharePoint list items to a csv file, and using the below code we can convert the particular csv file to excel file:

### Set input and output path
$inputCSV = "C:\somefolder\input.csv"
$outputXLSX = "C:\somefolder\output.xlsx"

### Create a new Excel Workbook with one empty sheet
$excel = New-Object -ComObject excel.application 
$workbook = $excel.Workbooks.Add(1)
$worksheet = $workbook.worksheets.Item(1)

### Build the QueryTables.Add command
### QueryTables does the same as when clicking "Data » From Text" in Excel
$TxtConnector = ("TEXT;" + $inputCSV)
$Connector = $worksheet.QueryTables.add($TxtConnector,$worksheet.Range("A1"))
$query = $worksheet.QueryTables.item($Connector.name)

### Set the delimiter (, or ;) according to your regional settings
$query.TextFileOtherDelimiter = $Excel.Application.International(5)

### Set the format to delimited and text for every column
### A trick to create an array of 2s is used with the preceding comma
$query.TextFileParseType  = 1
$query.TextFileColumnDataTypes = ,2 * $worksheet.Cells.Columns.Count
$query.AdjustColumnWidth = 1

### Execute & delete the import query

### Save & close the Workbook as XLSX. Change the output extension for Excel 2003

Reference URL:

How to export a CSV to Excel using Powershell


  • There is no direct inbuilt function to export in excel using PowerShell as like Export-CSV, so first we need to export to csv file, then we have to convert that file to excel.

Try if this works:

Install-Module importexcel

If it works, then after that you can use export-excel command.

New contributor
Timo Riikonen is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.