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?


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, privacy policy and cookie policy

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