Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View fabianneve's full-sized avatar

Fabian Neve fabianneve

View GitHub Profile
@fabianneve
fabianneve / SP_clearShortTermFileLockImpersonation.ps1
Created February 9, 2018 09:08
Clear short term file lock of a file in a SharePoint 2013+ document library when the file is still open by the user. Replace url, list (List Title) and item ID.
$web = get-spweb "https://domain/sitecollection/site"
$list = $web.Lists["Documents"]
$item = $list.Items.GetItemById(123)
$userId = $item.File.LockedByUser.ID
$user = $web.AllUsers.GetById($userId)
$impSite = New-Object Microsoft.SharePoint.SPSite($web.Url, $user.UserToken);
$impWeb = $impSite.OpenWeb();
$impList = $impWeb.Lists[$list.Title];
@fabianneve
fabianneve / SP_clearShortTermFileLock.ps1
Created February 9, 2018 09:03
Clear short term file lock of a file in a SharePoint 2013+ document library. Replace url, list (List Title) and item ID.
$web = get-spweb "https://domain/sitecollection/site"
$list = $web.Lists["Documents"]
$item = $list.Items.GetItemById(123)
$item.File.ReleaseLock($item.File.LockId)
$web.Dispose()
@fabianneve
fabianneve / changeDiscussionLabel.js
Last active January 17, 2018 12:23
Insert this script into a script editor (in between a script-tag <script type="text/javascript"> ) to change the default label into a custom one.
//self-executing anonymous function
(function () {
// String overrides
function DiscussionListViewStringOverride() {
Strings.STS.L_SPDiscHeroLinkAltText = "New Label"; //change "New Label" into your desired one, eg. "Create News"
Strings.STS.L_SPDiscHeroLinkFormat = "New Label"; //change "New Label" into your desired one, eg. "Create News"
}
DiscussionListViewStringOverride();
ExecuteOrDelayUntilScriptLoaded(DiscussionListViewStringOverride, "strings.js");
@fabianneve
fabianneve / addUserOrGroupToAllSiteCollectionAdministratorsFarmwide.ps1
Created January 15, 2018 10:23
This script adds a user or group to the Site Collection Administrators Group of every Site Collection Farm-wide. Define your User or Group in line 2.
#example: $AccountList = @("DOMAIN\User" , "DOMAIN\Group")
$AccountList = @("DOMAIN\User")
$wapps = Get-SPWebApplication
Foreach($webapp in $wapps)
{
foreach ($SiteCollection in $webapp.Sites)
{
write-host $SiteCollection.url
$spweb = Get-SPWeb $SiteCollection.url
@fabianneve
fabianneve / addUserOrGroupToAllSiteCollectionAdministratorsPerWebApplication.ps1
Created January 15, 2018 10:20
This script adds a user or group to the Site Collection Administrators Group of every Site Collection of a Web Application. Define your parameters in line 1 and line 2.
$AccountList = @("Domain\UserOrGroup")
$webapp = Get-SPWebApplication -Identity https://webapplicationurl/
foreach ($SiteCollection in $webapp.Sites)
{
write-host $SiteCollection.url
$spweb = Get-SPWeb $SiteCollection.url
foreach ($Account in $AccountList)
{
<script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
_spBodyOnLoadFunctionNames.push("ready");
function ready()
{
$("h3.ms-standardheader:contains('Question')").closest("tr").hide();
}
</script>
@fabianneve
fabianneve / printSpLibrary.txt
Last active November 14, 2017 12:34
Script, which hides all navigation bars and starts the print dialog
<style type="text/css">
#suiteBar{
display:none;
}
#s4-ribbonrow{
display:none;
}
#s4-titlerow{
display:none !important;
}
@fabianneve
fabianneve / CreateSearchServiceApplicationTopology.ps1
Last active November 6, 2017 09:20
Create a SharePoint 2013/2016 Search Topology on 4 nodes
# Source https://technet.microsoft.com/en-us/library/jj862356.aspx
<# Specify the new servers you want to add search components to, start a search service instance (ssi) on these servers and
create references to the search service instances #>
$hostA = Get-SPEnterpriseSearchServiceInstance -Identity "PRDS0270"
$hostB = Get-SPEnterpriseSearchServiceInstance -Identity "PRDS0271"
$hostC = Get-SPEnterpriseSearchServiceInstance -Identity "PRDS0272"
$hostD = Get-SPEnterpriseSearchServiceInstance -Identity "PRDS0273"
@fabianneve
fabianneve / embedGistInSharePoint.js
Last active October 20, 2017 13:08
If SharePoint hides the Script Code of a Gist, use this script
document._write = document.write;
document.write = function(str){
if (str.indexOf('<div id=\"gist-') != 0) {
if(str.indexOf('https://gist.github.com/stylesheets/gist/embed.css') == -1) {
// if you got this far it's not a github document.write call
document._write(str);
}
return;
}