Want to become a Vibe Coder? Join Vibe Coding Training here
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
Get all Sites and Subsites of a webapplication using powershell
WhatsApp
Abhay Shanker
11y
54.3
k
0
0
25
Blog
Sometimes we need to list all the sites and subsites and sub-subsites of one of the web application. We can do this by either coding or by powershell scripting. Coding is a tedious task so can prefer powershell as long as you have access to the server.
## SharePoint DLL
[
void
][System.Reflection.Assembly]::LoadWithPartialName(
"Microsoft.SharePoint"
)
$webApplicationURL = Read-Host
"Enter Web application"
$webApp = Get-SPWebApplication $webApplicationURL
if
($webApp -ne $
null
)
{
#Write-Host "Web Application : " + $webApp.Name
foreach($siteColl
in
$webApp.Sites)
{
if
($siteColl -ne $
null
)
{
Write-Host -foregroundcolor red
"Site Collection: "
$siteColl.Url
Get-SPSite $siteColl | Get-SPWeb -Limit All | Select Title, Url
}
else
{
Echo $siteColl
"does not exist"
}
}
}
else
{
Write-Host $webApplicationURL
"does not exist, check the WebApplication name"
}
Get all Sites and Subsites of a webapplication using powershell
People also reading
Membership not found