Skip to content

Instantly share code, notes, and snippets.

@Na0mir
Na0mir / GetItemWithSPQuery.cs
Last active January 3, 2016 23:49
Get SharePoint item (SPListItem) using CAML from column's name.
// ----------------------------------------------
// Author: Romain Blanchard
// Date: 21.01.2014
// Description: Get SharePoint item (SPListItem) using CAML from column's name.
// ----------------------------------------------
SPList Library = web.Lists[<ListName>];
SPQuery ItemQuery = new SPQuery();
ItemQuery.Query = "<Where><Eq><FieldRef Name=\"<ColumnName>\" /><Value Type='Text'>" + <Value> + "</Value></Eq></Where>";
SPListItemCollection ListItemCollection = Library.GetItems(ItemQuery);
@Na0mir
Na0mir / SendMail.ps1
Last active August 29, 2015 13:56
Send email with PowerShell
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 04.02.2014
# Description: Send email with PowerShell
# ----------------------------------------------
$serveur = "RBLA-SP2010-001.RBLA.com"
$expediteur = "romain@RBLA-SP2010-001.RBLA.com"
$destinataire = "test@RBLA-SP2010-001.RBLA.com"
$fichier = "D:\fichier.txt"
@Na0mir
Na0mir / DeleteAllSiteCollections.ps1
Last active August 29, 2015 13:56
Delete all site collections in a WebApplication.
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 06.02.2014
# Description: Delete all site collection in Web Application.
# ----------------------------------------------
$webappurl = "http://rbla-sp2010-001:81"
$webapp = Get-SPWebApplication $webappurl
foreach ($sites in $webapp.Sites)
{
@Na0mir
Na0mir / Create50SampleDocument.ps1
Last active August 29, 2015 13:56
Create x documents. Perfect to create sample document.
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 12.02.2014
# Description: Create x documents. Perfect to create sample document.
# ----------------------------------------------
01..50 | % { New-Item "Document$_.docx" -Value (Get-Date).toString() -itemType file}
@Na0mir
Na0mir / GetSPWebProperties.js
Last active December 13, 2017 16:38
Get SPWeb properties (property bag) using Javascript.
// ----------------------------------------------
// Author: Romain Blanchard
// Date: 20.02.2014
// Description: Get SPWeb properties (property bag) using Javascript.
// ----------------------------------------------
//Execute le script au chargement de la page, juste après le sp.js
ExecuteOrDelayUntilScriptLoaded(getAllWebProperty, "SP.js");
var properties;
@Na0mir
Na0mir / ImportTermsetFromCSV.ps1
Last active August 29, 2015 13:56
Import termset from CSV file. CSV format is standard TermSet format.
# ----------------------------------------------
# Author: Microsoft
# Date: 27.02.2014
# Description: Import termset from CSV file.
# ----------------------------------------------
function ImportTermSet([Microsoft.SharePoint.Taxonomy.TermStore]$store, [string]$groupName, [PSCustomObject]$termSet) {
function ImportTerm([Microsoft.SharePoint.Taxonomy.Group]$group,
[Microsoft.SharePoint.Taxonomy.TermSet]$set,
[Microsoft.SharePoint.Taxonomy.Term]$parent,
@Na0mir
Na0mir / UpdatePermissions.ps1
Last active August 29, 2015 14:14
This script remove / add / update permissions of folders and libraries.
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 04.02.2015
# Description: This script remove / add / update permissions of folders and libraries.
# ----------------------------------------------
# Parameters
param(
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
@Na0mir
Na0mir / CopyUsersAndGroups.ps1
Last active August 29, 2015 14:14
Copy account's (users and groups), to an other site. Edit login's prefix part in the same time.
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 29.03.2013
# Description: Copy account's (users and groups), to an other site. Edit login's prefix part in the same time.
# ----------------------------------------------
## Import Powershell module if the script is launched from normal powershell commandline
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
## Function that reads the INI configuration file
@Na0mir
Na0mir / UpdatePagelayout.ps1
Last active August 29, 2015 14:14
Get all pages located in "Pages" library and change theirs page layout.
# ----------------------------------------------
# Author: Romain Blanchard
# Date: 20.06.2012
# Description: Get all pages located in "Pages" library and change theirs page layout.
# ----------------------------------------------
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
# Variables
@Na0mir
Na0mir / ExportTermsetIntoCSV.ps1
Last active August 29, 2015 14:15
Export all termsets from all groups into CSV files.
# ----------------------------------------------
# Author: Microsoft
# Date: 09.10.2013
# Description: Export all termsets from all groups into CSV files.
# ----------------------------------------------
$siteUrl = "<Enter URL of Central Administration>"
$outputDir = "<Enter export output path>"