C# Corner
Tech
News
Videos
Forums
Trainings
Books
Events
More
Interviews
Jobs
Live
Learn
Career
Members
Blogs
Challenges
Certifications
Bounties
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 Web Parts In A Site Collection
WhatsApp
Guest User
8y
4
k
0
0
25
Blog
Create a ps1 extension file and save it in your local path.
Change the highlighted part with your site collection url.
function
EnumAllWebPartsOfSiteCollection($Url) {
$site =
new
- object Microsoft.SharePoint.SPSite $Url
$allFiles = @()
foreach($web
in
$site.AllWebs) {
Write - Host
"Processing Web:"
$web.Url - NoNewLine
if
([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)) {
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pages = $pWeb.PagesList
foreach($item
in
$pages.Items) {
$allFiles += $item.File
}
}
$pages = $
null
$pages = $web.Lists[
"Site Pages"
]
if
($pages) {
foreach($item
in
$pages.Items) {
$allFiles += $item.File
}
}
foreach($file
in
$web.Files) {
$allFiles += $file
}
$web.Dispose()
Write - Host
" - completed"
}
foreach($file
in
$allFiles) {
$fileUrl = $Url + $file.ServerRelativeUrl
$manager = $file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
$wps = $manager.webparts
$manager.Dispose()
$wps | select - object @ {
Expression = {
$file.Web.Url
};
Label =
"Web URL"
}, @ {
Expression = {
$fileUrl
};
Label =
"Page URL"
}, DisplayTitle, IsVisible, @ {
Expression = {
$_.GetType().ToString()
};
Label =
"Type"
}
}
$site.Dispose()
}
$row = EnumAllWebPartsOfSiteCollection(
'http://hvsp01:31300/sites/Test'
)
$row | Out - GridView
Open Management Shell as an administrator.
Run the PS script using the path along with the file name in the management shell.
Here is the required output.
People also reading
Membership not found