TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
SharePoint: Powershell Script to get the List of Sites under a Web Application
Karthik Muthu Karuppan
Apr 29
2015
Code
1.8
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
$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
SharePoint
PowerShell Script to get List
Sites list under web application