Subscribe:

Labels

Showing posts with label sharepoint2010. Show all posts
Showing posts with label sharepoint2010. Show all posts

Wednesday, August 12, 2020

List All WebParts

 #----------------------------------------------------------------------------- 

# Name:             list-all-webparts.ps1  

# Description:      This script will create a list of all web parts in all 

#                   pages in a site collection.

#                     

# Usage:            Run the script passing three paramters: Url, Folder and WP. 

# Url Accepts multiple values (comma separated).

#                   Folder is the destination of the report.

# WP is the name of the web part (optional).

# By:               Riccardo Celesti blog.riccardocelesti.it

#----------------------------------------------------------------------------- 



Param([Parameter(Mandatory=$true)] 

      [String] 

      $Url,

      [Parameter(Mandatory=$true)] 

      [ValidateScript({Test-Path $_ -PathType 'Container'})]

      [String] 

      $folder,

  [Parameter(Mandatory=$false)]

      [String] 

      $WP


if ((gsnp Microsoft.SharePoint.Powershell -EA SilentlyContinue) -eq $null){

    asnp Microsoft.SharePoint.Powershell -EA Stop

}


$filename = "WebPartsReport_" + (Get-Date).ToFileTimeUtc().ToString() + ".csv"

$filenamewp = "WebPartsReport_" + $WP.Replace(" ","-") + "_" + (Get-Date).ToFileTimeUtc().ToString() + ".csv"


$logfile = Join-Path $folder $filename

$logfilewp = Join-Path $folder $filenamewp


$urlArray = $Url.Split(",")


$header = "File Url, Web Part Title, Web Part Type, Visible"


ac $logfile $header

ac $logfilewp $header


$logfilecontrol = $null


foreach ($SPsite in $urlArray){

    Get-SPSite $SPsite| % {


        foreach ($web in $_.AllWebs){

        

            if ([Microsoft.SharePoint.Publishing.PublishingWeb]::IsPublishingWeb($web)){


                $library = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)

                $pages = $library.PagesList

            

                foreach ($file in $pages.Items){


                    $fileUrl = $web.Url + "/" + $file.File.Url


                    $manager = $file.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);


                    $webparts = $manager.webparts


                    $webparts | %{

                        ac $logfile "$fileUrl, $($_.DisplayTitle), $($_.GetType().ToString()), $($_.IsVisible)"

if ($_.DisplayTitle -match $WP -and -not [string]::IsNullOrEmpty($WP)){

ac $logfilewp "$fileUrl, $($_.DisplayTitle), $($_.GetType().ToString()), $($_.IsVisible)"


                            $logfilecontrol = 1

}

                    }

                }


                $sitepages = [Microsoft.Sharepoint.Utilities.SpUtility]::GetLocalizedString('$Resources:WikiLibDefaultTitle',"core",$web.UICulture.LCID)


                $pages = $null

                $pages = $web.Lists[$sitepages]


                if ($pages -and $pages.ItemCount -gt 0){


                    foreach ($file in $pages.Items) {

                        $fileUrl = $web.Url + "/" + $file.File.Url


                        $manager = $file.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);


                        $webparts = $manager.webparts


                        $webparts | %{

                            ac $logfile "$fileUrl, $($_.DisplayTitle), $($_.GetType().ToString()), $($_.IsVisible)"

if ($_.DisplayTitle -match $WP -and -not [string]::IsNullOrEmpty($WP)){

ac $logfilewp "$fileUrl, $($_.DisplayTitle), $($_.GetType().ToString()), $($_.IsVisible)"


                                $logfilecontrol = 1

}

                        }   

                    }

                }

            } else {

                $sitepages = [Microsoft.Sharepoint.Utilities.SpUtility]::GetLocalizedString('$Resources:WikiLibDefaultTitle',"core",$web.UICulture.LCID)


                $pages = $null

                $pages = $web.Lists[$sitepages]


                if ($pages){


                    foreach ($file in $pages.Items) {

                        $fileUrl = $web.Url + "/" + $file.File.Url


                        $manager = $file.file.GetLimitedWebPartManager([System.Web.UI.WebControls.Webparts.PersonalizationScope]::Shared);


                        $webparts = $manager.webparts


                        $webparts | %{

                            ac $logfile "$fileUrl, $($_.DisplayTitle), $($_.GetType().ToString()), $($_.IsVisible)"

                            

                            if ($_.DisplayTitle -match $WP -and -not [string]::IsNullOrEmpty($WP)){

ac $logfilewp "$fileUrl, $($_.DisplayTitle), $($_.GetType().ToString()), $($_.IsVisible)"


                                $logfilecontrol = 1

}

                        }

                    }

                }

            }

        }

    }

}


notepad.exe $logfile


if ($logfilecontrol -eq 1){

    notepad.exe $logfilewp

}

Thursday, September 27, 2018

Clear sharepoint cache


## SharePoint Server 2013: PowerShell Script To Reset The Config Cache On All Servers In A Farm ##


Add-PSSnapin Microsoft.SharePoint.PowerShell
$Servers = Get-SPServer | ? {$_.Role -ne "Invalid"} | Select -ExpandProperty Address
Write-Host "This script will reset the SharePoint config cache on all farm servers:"
$Servers | Foreach-Object { Write-Host $_ }
Write-Host "Press enter to start."
Read-Host
Invoke-Command -ComputerName $Servers -ScriptBlock {
    try {
        Write-Host "$env:COMPUTERNAME - Stopping timer service"
        Stop-Service SPTimerV4
        $ConfigDbId = [Guid](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0\Secure\ConfigDB' -Name Id).Id #Path to the '15 hive' ConfigDB in the registry
        $CacheFolder = Join-Path -Path ([Environment]::GetFolderPath("CommonApplicationData")) -ChildPath "Microsoft\SharePoint\Config\$ConfigDbId"
        Write-Host "$env:COMPUTERNAME - Clearing cache folder $CacheFolder"
        Get-ChildItem "$CacheFolder\*" -Filter *.xml | Remove-Item
        Write-Host "$env:COMPUTERNAME - Resetting cache ini file"
        $CacheIni = Get-Item "$CacheFolder\Cache.ini"
        Set-Content -Path $CacheIni -Value "1"
        }
    finally{
        Write-Host "$env:COMPUTERNAME - Starting timer service"
        Start-Service SPTimerV4
        }
}


Remove IIS logs

cls
$limit = (Get-Date).AddDays(-7)

Import-Module WebAdministration
$iisdir = (Get-WebConfigurationProperty "/system.applicationHost/sites/siteDefaults" -name logfile.directory).Value

if($iisdir.Contains("%SystemDrive%"))
{

$iisdir = $iisdir.Replace("%SystemDrive%","C:");
}
Write-Host "iisdirectory path : "$iisdir

Get-ChildItem $iisdir -Recurse | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit } | Remove-Item -Force

Write-host "Deledted files which are before date :"$limit -ForegroundColor Green
write-host "Completed Successfully Deleting Files from Path: " $iisdir -ForegroundColor Green

Wednesday, February 8, 2012

List Throttling in Sharepoint2010

SharePoint 2010 has  number of new features centered around working with large lists.  A new feature is incorporated into SPS 2010 for putting limit on the amount of data to be retrieved from the servers. The feature is called List Throttling.
SP2010 can support up to 50 million items in a list now, but you don’t obviously want to return all of those in a single query.  To aid with this, SP2010 introduces list throttling settings (configured at the web application level), that allow you to specify how many items a user can query before the throttle kicks in and aborts the query.  At the time of writing, these limits are set to 5,000 for normal users and 20,000 for super users.  Remember you can change these settings if you so choose.  I’ll be curious to see what numbers people actually end up running with.  This applies to anything that queries the list whether its through the SharePoint UI or from your own custom code.  If the user submits a query that is too large, the SharePoint UI will tell the user that the query is too big and they need to filter it.
List throttling is managed through web application. Click on Application Management --> Manage Web Applications.  Select the web application you want to configure list throttling, then in the ribbon click on the General Settings drop down and select the Resource Throttling item. Below figure shows how to enable list throttling in a web application.

In order to retrieve information using the object model in order to retrieve up to the number of items specified in the List query size threshold for auditors and administrators property, there is a property you need to set in your query object. 
The property is called QueryThrottleMode and it applies to the SPQuery andSPSiteDataQuery classes.  You simply set this property to override and then use your class instance to query. 
using (SPSite oSite = new SPSite("http://sp2010:1234")) 
{
using (SPWeb oWeb = oSite.RootWeb)
{
SPList oList = oWeb.Lists["Test List"];

SPQuery oQuery = new SPQuery();
oQuery.QueryThrottleMode = SPQueryThrottleOption.Override;


            SPListItemCollection oListColl = oList.GetItems(oQuery);
            //Your custom logic here for processed data
}
}
Enhanced by Zemanta

sharepoint long Operation example using object model code

.  In the following example I have use LongOperation using sharepoint Splongoperation class. I have created a custom Web Part that has a button on it to create a site where I need perform some custom actions.

As a SharePoint Developer, you can wrap your lengthy operations code with the SPLongOperation to display the spinning wheel processing screen whenever you are executing long duration code-block to improve the user experience. After invoking SPLongOperation object, you can start and stop the long operation using Begin() and End() methods. Alternatively, you can use the LeadingHTML and TrainingHTML properties to customize the message on the processing screen.
protected void btnProvisionSites_Click(object sender, EventArgs e)
{
    //Long Operation Code
    using (SPLongOperation longOperation = new SPLongOperation(this.Page))
    {
        //Custom Messages on the Spinning Wheel Screen
        longOperation.LeadingHTML = "Provisioning Sites";
        longOperation.TrailingHTML = "Please wait while the sites are being provisioned.";
        //Start the long operation
        longOperation.Begin();
        //Your Long Operation Code Goes Here...
        // e.g. Site provisioning code
        //End the long operation
        string redirectURL = SPContext.Current.Web.Url;
        longOperation.End(redirectURL);
    }
}
Enhanced by Zemanta