Skip to content

Instantly share code, notes, and snippets.

View jcallaghan's full-sized avatar

James Callaghan jcallaghan

View GitHub Profile
@jcallaghan
jcallaghan / Export-SPSolutions.ps1
Last active October 24, 2019 14:58
Download and backup deployed SharePoint solutions from the config database. See https://jcallaghan.com/2011/09/backup-and-download-solutions-in-sharepoint-from-the-configuration-database/ for more information. #Website
# Download and backup deployed SharePoint solutions from the config database
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$dir = "C:\Solutions\"
$solutions = Get-SPSolution
if(!$solutions){
write-host "No solutions found." -foregroundcolor Red
}else{
@jcallaghan
jcallaghan / Remove-SPQuickLaunchLinks.ps1
Last active October 24, 2019 14:58
Remove links from the quick launch in classic SharePoint Team sites. See https://jcallaghan.com/2011/10/clear-the-sharepoint-quick-launch-using-powershell/ for more information. #Website
## The following four lines only need to be declared once in your script.
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes","Description."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No","Description."
$cancel = New-Object System.Management.Automation.Host.ChoiceDescription "&Cancel","Description."
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no, $cancel)
## Use the following each time your want to prompt the use
$title = "Title"
$message = "Question?"
$result = $host.ui.PromptForChoice($title, $message, $options, 1)
@jcallaghan
jcallaghan / Set-SPManagedPath.ps1
Last active October 24, 2019 14:59
Administer managed paths in SharePoint using PowerShell. See https://jcallaghan.com/2011/11/working-with-managed-paths-in-sharepoint-using-powershell/ for more information. #Website
# Administer managed paths in SharePoint using PowerShell.
# https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/get-spmanagedpath?view=sharepoint-ps
# Get managed paths
Get-SPManagedPath -WebApplication https://sharepoint.jcallaghan.com
## New explicit managed path
New-SPManagedPath -RelativeURL "projectsdirectory" -Explicit -WebApplication https://sharepoint.jcallaghan.com
## New wildcard managed path
@jcallaghan
jcallaghan / SharePointHideRichTextField.xsl
Last active October 24, 2019 15:01
Hide the rich text editor in SharePoint 2007 and SharePoint 2010 using XSLT. See https://jcallaghan.com/2011/12/hiding-an-empty-rich-text-column-in-xslt/ for more information. #Website
// SharePoint 2007 = 59
// SharePoint 2010 = 37
<!-- any conditional formatting would go here -->
<xsl:if test="string-length(@Body) &gt; 37">
<!-- conditional formatting and presentation would go here -->
<div class="item body">
<xsl:value-of disable-output-escaping="yes" select="@Body"/>
</div>
</xsl:if>
@jcallaghan
jcallaghan / SharePointSecurityTrimmedLinks.ps1
Last active October 24, 2019 15:00
Create a security trimmed link. See https://jcallaghan.com/2012/06/security-trimmed-top-navigation-links/ for more information. #Website
@jcallaghan
jcallaghan / SharePointSecondStageRecycleBin.ps1
Last active October 24, 2019 15:02
This script will delete items from the Second Stage Recycle Bin that are older than XX days. See https://jcallaghan.com/2014/04/working-with-sharepoints-second-stage-recycle-bin-in-powershell/ for more information. #Website
Add-PSSnapin Microsoft.SharePoint.PowerShell
#Variables
$i = 0
#SharePoint Site Collection URL
$url = "https://sharepoint.jcallaghan.com"
#$url = Read-Host "Enter a valid URL to a SharePoint Site Collection?"
#if($url -eq ""){write-host "No URL provided." -foregroundcolor Red; Exit}
@jcallaghan
jcallaghan / Set-SPNewHomepage.ps1
Last active October 24, 2019 15:03
This function changes the name of the current homepage and renames a page to Home.aspx. It does of course assume the current home page is Home.aspx. The welcome page URL is case sensitive. See https://jcallaghan.com/2019/06/switch-between-modern-sharepoint-homepages-using-pnp-powershell/ or more information. #Website
<#
.SYNOPSIS
Easily replace the current homepage with an alternative page you have created.
.DESCRIPTION
This function changes the name of the current homepage and renames a page to Home.aspx.
The script currently only works when the homepage is /sitepages/home.aspx.
It does of course assume the current homepage is Home.aspx. The welcome page URL is case sensitive.
A switch to remove the previous homepage rather than rename it is also included.
.EXAMPLE
Set-NewHomepage -siteurl https://demo.sharepoint.com/sites/intranet -pagerelativeurl /sitepages/newhome1.aspx -removeprevious:$false
{
"headerEmphasis":null,
"themeKey":null,
"name":"SharePoint Hub Site",
"url":"https://[tenant].sharepoint.com/sites/[site]",
"logoUrl":null,
"usesMetadataNavigation":false,
"megaMenuEnabled":true,
"navigation":[{
"Id":2004,
function Get-SPOHubSiteNavigation{
<#
.SYNOPSIS
Exports the hub navigation for the SPO site provided to CSV.
.DESCRIPTION
This custom function gets the Hub site navigation links for the provided SPO site.
It then iterates through each of the links and builds a collection to export to CSV.
This collection can also be integrated using pipe functions.