In this post, let me tell you How to get the list of sites under a Wen Application using Powershell in SharePoint 2013. Now, It’s time to write the following code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm $LogFile = ".\GetSubsitePatch-$LogTime.rtf" # Add SharePoint PowerShell Snapin if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) { Add-PSSnapin Microsoft.SharePoint.Powershell } $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent Set-Location $scriptBase #Deleting any .rtf files in the scriptbase location $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf if($FindRTFFile) { foreach($file in $FindRTFFile) { remove-item $file } } start-transcript $logfile $Output = $scriptBase + "\" + "SiteDetails.csv"; "WebApplication" + "," + "SiteCollection" + "," + "Webs" | Out-File -Encoding Default -FilePath $Output; $webapp = read-host "Enter the web app URL under which you want to list out the subsites" $testWebApp = get-spwebapplication $webapp -ea silentlycontinue if($testWebApp -ne $null) { $empty = "" $webapp + "," + $empty + "," + $empty | Out-File -Encoding Default -Append -FilePath $Output; $sites = get-spsite -limit all -webapplication $webapp foreach($site in $sites) { $empty + "," + $site.url + "," + $empty | Out-File -Encoding Default -Append -FilePath $Output; foreach($web in $site.allwebs) { Write-host $web.url -fore cyan $empty + "," + $empty + "," + $web.url | Out-File -Encoding Default -Append -FilePath $Output; } } } else { write-host "Invalid Web app.... please check the URL" -fore cyan } stop-transcript |
I hope it works for you! Good luck with that.
SharePoint 2013 Hosting Recommendation
HostForLIFE.eu’s SharePoint 2013 Hosting solution offers a comprehensive feature set that is easy-to-use for new users, yet powerful enough for the most demanding web developer expert. Hosted SharePoint Foundation 2013 is the premiere web-based collaboration and productivity enhancement tool on the market today. With SharePoint 2013 Foundation, you can quickly access and manage documents and information anytime, anywhere though a Web browser in a secure and user friendly way. SharePoint hosting services start at only at €9.99/mo, allowing you to take advantage of the robust feature set for a small business price. HostForLIFE.eu offers a variety of hosted SharePoint Foundation 2013 plans as well as dedicated SharePoint 2013 Foundation options.