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 Find Lists with Null Default View in SharePoint 2010
Karthik Muthu Karuppan
Feb 19
2015
Code
1.9
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
FindSPNullDefaultVie
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
$LogFile =
".\FindSPNullDefaultViewPatch-$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
function
FindSPNullDefaultView{
[cmdletbinding()]
param(
[parameter(ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True,Mandatory=$True)]
[string[]]$url
)
Begin{
$const_verbosepreference = $verbosepreference
$verbosepreference =
"Continue"
Try { [
void
] [System.Reflection.Assembly]::LoadWithPartialName(
"Microsoft.SharePoint"
) }
Catch {
Write-Warning
"Failed to Load REQUIRED .NET Framework Assembly Class...exiting script!"
Break
}
$array = @()
}
Process{
Try{
$SiteCollection = New-Object Microsoft.SharePoint.SPSite($url)
Foreach($Site
in
$SiteCollection.AllWebs){
Write-Verbose
"$($Site.Url)"
Foreach ($List
in
$Site.Lists){
Try{
If($List.DefaultView -eq $
null
){
$props = @{
Title=$($List.Title)
ItemCount=$($List.ItemCount)
Author=$($List.Author)
LastItemModifiedDate=$($List.LastItemModifiedDate)
ParentWebUrl=$($List.ParentWebUrl)
BaseType=$($List.BaseType)
RootFolder=$($List.RootFolder)
Hidden=$($List.Hidden)
}
$array += New-Object PSObject -property $props
}
} Catch { Write-Verbose
"Unable to load $List.DefaultViewUrl"
}
}
}
$SiteCollection.Dispose();
} Catch { Write-Verbose
"Unable to locate site for $($url)"
}
}
End{
$array
$verbosepreference = $const_verbosepreference
}
}
$siteCollectionURL = read-host
"Enter the site collection url "
FindSPNullDefaultView $siteCollectionURL
stop-transcript
SharePoint
Find Lists with Null Default View in SharePoint