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
Powershell Script to Check all Sharepoint Page's Webpart
Manish Loke
Apr 01
2016
Code
808
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#Add SharePoint cmdlets reference
Add - PSSnapin microsoft.sharepoint.powershell - ErrorAction SilentlyContinue
function enumerateWebParts($Url)
{
$site =
new
-
object
Microsoft.SharePoint.SPSite $Url
foreach
($web
in
$site.AllWebs)
{
if
([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web))
{
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$pages = $pWeb.PagesList
Write - Host
"Processing Web:"
$pWeb.Url
"http://bmfthnitd125:2222/"
- ForegroundColor Magenta
foreach
($item
in
$pages.Items)
{
$fileUrl = $webUrl +
"/"
+ $item.File.Url
Write - Host
" "
$fileUrl - ForegroundColor Green
$manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
$wps = $manager.webparts
$wps | select -
object
@
{
Expression =
{
$pWeb.Url
};
Label =
"Web URL"
}, @ {
Expression =
{
$fileUrl
};
Label =
"Page URL"
}, DisplayTitle, IsVisible, @
{
Expression =
{
$_.GetType().ToString()
};
Label =
"Type"
}
}
}
else
{
Write - Host
" Not a publishing web:"
$web.Url
". Looking for Site Pages library."
- ForegroundColor Magenta
$pages = $
null
$pages = $web.Lists[
"Pages"
]
if
($pages)
{
Write - Host
" "
$pages.Title
"found."
- ForegroundColor Green
foreach
($item
in
$pages.Items)
{
$fileUrl = $webUrl +
"/"
+ $item.File.Url
$manager = $item.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);
$wps = $manager.webparts
$wps | select -
object
@
{
Expression =
{
$pWeb.Url
};
Label =
"Web URL"
}, @ {
Expression =
{
$fileUrl
};
Label =
"Page URL"
}, DisplayTitle, IsVisible, @
{
Expression =
{
$_.GetType().ToString()
};
Label =
"Type"
}
}
Write - Host
"Press any key to continue..."
$Host.UI.RawUI.ReadKey(
"NoEcho,IncludeKeyUp"
) > $
null
}
else
{
Write - Host
" Site Pages library not found."
- ForegroundColor Red
}
}
Write - Host
"Press any key to continue..."
$Host.UI.RawUI.ReadKey(
"NoEcho,IncludeKeyUp"
) > $
null
Write - Host
"... completed processing"
$web
"..."
- ForegroundColor Magenta
Write - Host
"Press any key to continue..."
$Host.UI.RawUI.ReadKey(
"NoEcho,IncludeKeyUp"
) > $
null
}
}
$row = enumerateWebParts(
'http://bmfthnitd125:2222/'
)
$row | Out - GridView
Write - Host
"Press any key to continue..."
$Host.UI.RawUI.ReadKey(
"NoEcho,IncludeKeyUp"
) > $
null
Powershell Script
Sharepoint