Skip to content

Instantly share code, notes, and snippets.

View kasuken's full-sized avatar
:octocat:
Authoring courses

Emanuele Bartolesi kasuken

:octocat:
Authoring courses
View GitHub Profile
@kasuken
kasuken / AddItemToLinksList.ps1
Created June 13, 2014 10:44
SharePoint 2013: Add item to links list with PowerShell
@kasuken
kasuken / ConsoleLogHelper.cs
Created December 31, 2014 11:36
An helper to log in a console application with colors and log level priority
public static class LogHelper
{
enum LogLevel
{
Debug,
Info,
Warning,
Error
}
@kasuken
kasuken / jslinktoalldocumentlibrary.ps1
Created January 20, 2015 19:34
Apply a JS Link file to all document library in all site of a site collection
#Load powershell snapin
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
#Get site collection details
$site = Get-SPSite http://mysite
#Get all web sites in the site collections
$websites = $s.AllWebs
foreach($website in $websites)
{
Write-Host $website.Title -foreground Yellow
@kasuken
kasuken / disableMDM.ps1
Created March 30, 2015 07:52
Disable Minimal Download Strategy in all Site Collections
$webApp = Get-SPWebApplication -Identity http://webapplication:8080
$siteCollection =$webApp | Get-SPSite -limit all
foreach ($site in $siteCollection)
{
$webs = $site | Get-SPweb -limit all
foreach ($web in $webs)
{
$url = $web.URL
write-host "Web URL = " $url -foregroundcolor "blue"
@kasuken
kasuken / SqlCommandStatistics.cs
Created October 27, 2017 11:55
Retrieve the SQL Server Statistics for a SQL Command
public Dictionary<string,string> Run(string connectionString, string query)
{
using (var sqlConnection = new SqlConnection(connectionString))
{
sqlConnection.StatisticsEnabled = true;
sqlConnection.Open();
using (var cmd = new SqlCommand(query, sqlConnection))
{
@kasuken
kasuken / GravatarHelper.cs
Last active May 20, 2018 16:14
Create a Gravatar Link with C#
public class GravatarHelper
{
private string CalculateHash(string email)
{
MD5 md5Hasher = MD5.Create();
byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(email));
StringBuilder sBuilder = new StringBuilder();
@kasuken
kasuken / AllItem.aspx
Created January 3, 2019 10:09
SharePoint 2013/2016 TreeView
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<table style="width: 100%">
<tr valign="top">
<td width="20%">
<SharePoint:SPHierarchyDataSourceControl ID="docLibDataSource" runat="server" RootContextObject="List" ShowFolderChildren="True" EnableViewState="false"></SharePoint:SPHierarchyDataSourceControl>
<SharePoint:SPTreeView ID="doclibtreeview" runat="server" DataSourceID="docLibDataSource" EnableViewState="false" ExpandDepth="2" SelectedNodeStyle-CssClass="ms-tvselected"></SharePoint:SPTreeView>
</td>
@kasuken
kasuken / RestartSharePoint.cmd
Created June 11, 2019 04:58
A CMD script to restart all SharePoint services and IIS (it works on SP2010, SP2013, SP2016, SP2019)
@echo off
@echo Stopping Sharepoint services...
@echo Restarting The SharePoint Timer Service...
net stop SPTimerV4
net start SPTimerV4
@echo Restarting The SharePoint Administration Service...
@kasuken
kasuken / EmptySiteCollectionsRecycleBin.ps1
Last active June 19, 2019 09:49
Powershell script to remove an SPOsite (from the recycle bin, as well)
$username = ""
$password = ""
$Password = ConvertTo-SecureString -String $password -AsPlainText -Force;
$Credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password
Connect-SPOService -Url "https://[tenant]-admin.sharepoint.com" -Credential $Credentials
Get-SPODeletedSite | Remove-SPODeletedSite
@kasuken
kasuken / RestartSP.cmd
Created November 15, 2019 09:21
A simple command file to restart all SharePoint 2016 services on the server
@echo off
@echo Stopping Sharepoint services...
@echo Restarting The SharePoint Timer Service...
net stop SPTimerV4
net start SPTimerV4
@echo Restarting The SharePoint Administration Service...