Créer un site internet

Blog

Sharepoint Powershell Clear Search Cache

On 28/09/2018

Stop-Service SPTimerV4
$folders = Get-ChildItem C:\ProgramData\Microsoft\SharePoint\Config
foreach ($folder in $folders)
{
$items = Get-ChildItem $folder.FullName -Recurse
foreach ($item in $items)
{
if ($item.Name.ToLower() -eq "cache.ini")
{
$cachefolder = $folder.FullName
}
}
}
$cachefolderitems = Get-ChildItem $cachefolder -Recurse
foreach ($cachefolderitem in $cachefolderitems)
{
if ($cachefolderitem -like "*.xml")
{
$cachefolderitem.Delete()
}
}
 
$a = Get-Content $cachefolder\cache.ini
$a = 1
Set-Content $a -Path $cachefolder\cache.ini
 
read-host "Do this on all your SharePoint Servers and THEN press ENTER"
Start-Service SPTimerV4

testsOnly

On 28/09/2018

coucou

Powershell Batch Delete

On 28/09/2018

param($url="http://fdi-sp2013-1:8080/sites/testJS_publishing2",
$listTitle="testDelete")
 
clear;
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
#get the spweb
$web = Get-SPWeb -Identity $url
#get list by title
$list = $web.Lists[$listTitle];
$list.Title
 
#your caml query
$query = New-Object -TypeName Microsoft.SharePoint.SPQuery
$rowLimit= 100
 
$query.ViewXml = "<View><ViewFields><FieldRef Name='ID'><FieldRef Name='FileRef'></FieldRef></FieldRef></ViewFields><Query><Where></Eq></Where></Query><RowLimit>$($rowLimit)</RowLimit></View>";
 
$items = $list.GetItems($query)
 
#number items
"items.Count : $($items.Count)"
 
#the number of items that will be deleted
$batch = "<?xml version=""1.0"" encoding=""UTF-8""?><Batch>";
foreach($item in $items)
{
$batch +="<Method><SetList Scope=""Request"">$($list.ID)</SetList><SetVar Name=""ID"">$($item.Id)</SetVar><SetVar Name=""owsfileref"">$($item["FileRef"])</SetVar><SetVar Name=""Cmd"">Delete</SetVar></Method>"
$item.Id
$item["FileRef"]
}
$batch +="</Batch>"
 
#proceed to deletion
$web.ProcessBatchData($batch);
$web.Dispose()
Write-Host "list is empty bu warnig limit in code rowLimit $($rowLimit)"
sharepoint powershell tips

Sharepoint Powershell tips

On 28/09/2018

To add your assembly in powershell script / console

Add-Type -AssemblyName System.Web

 

Copy string to clipboard

"your datas" | c:\windows\system32\clip.exe

 

Reference sharepoint in powershell console

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

 

Set your execution policy if you see this message

Impossible de charger le fichier D:\FDI\wordPress\ps1\EncodeHtml.ps1, car l’exécution de scripts est désactivée sur ce système. Pour plus
d’informations, consultez about_Execution_Policies à l’adresse https://go.microsoft.com/fwlink/?LinkID=135170.
+ CategoryInfo : Erreur de sécurité : (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess

set-executionpolicy -executionpolicy unrestricted

powershell.exe -executionpolicy unrestricted -command .\test.ps1

 

Sort and filter your collections

$l.Fields | select internalname, title, type, hidden | Where-Object {$_.Hidden -eq $false} | Sort-Object -Property internalname | Format-Table

get spfields by group

$w.Fields | Where-Object {$_.Group -eq "Site colums FDI"} | select internalName, typeasstring

List files in folder and copy to clipboard

$files = ls | select name

$files | c:\windows\system32\clip.exe

 

Regular expression to check file names

"toto.spx" -match "^[a-zA-Z0-9._ -]+$"

 

Load an assembly

Import-Module ".\Microsoft.SharePoint.Client.Runtime.dll"

 

Get logs from all servers on sharepoint farm

Merge-SPLogFile -Path "C:\temp\FarmMergedLog41.log" -Overwrite -Level Unexpected -StartTime (Get-Date).AddMinutes(-20)

Merge-SPLogFile -Path "C:\temp\FarmMergedLog22.log" -Overwrite -Correlation "52b2019e-d446-70aa-8f27-8efc5ec7f143" -StartTime (Get-Date).AddMinutes(-90)

 

Open a powershell console as another account

Start-Process powershell.exe -Credential "domain\spadmin" -NoNewWindow -ArgumentList "Start-Process powershell.exe -Verb runAs"

 

Export webpart from page

http://fdi-sp2013-1/_vti_bin/exportwp.aspx?pageurl=http://fdi-sp2013-1/Lists/Pratique/PratiqueHome.aspx&guidstring=84e04c62-3eb5-424e-a7f9-3219ff89d51c

 

Create a site collection

New-SPSite -Template STS#0 -OwnerAlias fdi\spdev -Url http://fdi-sp2013-1/sites/test6541 -Verbose -Confirm:$false -Language 1036 -Name test987 -Description oio

 

Do not use jquery $(document).ready(function () {

Use instead :

_spBodyOnLoadFunctionNames.push("loadAnnonce");//loadAnnonce is function loadAnnonce() called

 

Edit page on url change

?ControlMode=Edit&DisplayMode=Design

 

List assemblies

[AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.Location -ne $null -and $_.Location -like "*t.Client.*"}

 

Use stringBuilder to mange string concat

$stringBuilder = New-Object System.Text.StringBuilder

 

List of all sharepoint features

csv format

xlsx format