Live Webinar: Prompt Engineering: Skill Everyone Must Learn Today
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
SharePoint: Powershell Script to get the List of Sites under a Web Application
WhatsApp
Karthik Muthu Karuppan
Apr 29
2015
1.8
k
0
0
$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
Up Next
SharePoint: Powershell Script to get the List of Sites under a Web Application