I want to extract list of site collection of one of the webapplication using powershell.

I found this url which does the same thing. But i want result in a text file.


How to get result in text file?

  • Have your searched on "Powershell write to text file"? Commented Sep 4, 2015 at 12:01

3 Answers 3


Just use the cmdlt Out-File.

get-spsite -limit all -WebApplication http://yourWebapplicationUrl | Out-File -FilePath "C:\Users\YourUserName\Documents\spSites.txt"

I have used below code to list all site collections from a Web Application into a txt file

Add-PSSnapin "Microsoft.SharePoint.PowerShell"
Get-SPWebApplication http://yourwebapp.com | Get-SPSite | Select ID, Url | Out-File -FilePath "D:\spSites.txt"

The above solutions are fine. But you may encounter a problem with long site names. To make sure you get long string names use:

  get-spsite -limit all -WebApplication http://yourWebapplicationUrl | Ft -autosize -wrap | Out-File -FilePath "PathToYourFile" 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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