$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-transcriptThis program describe to PowerShell Script to Find Lists with Null Default View in SharePoint 2010.
