Skip to content

Instantly share code, notes, and snippets.

View kliemohn's full-sized avatar

Kirk Liemohn kliemohn

View GitHub Profile
@kliemohn
kliemohn / AddModernPageByline
Last active July 25, 2019 20:38
Code to add the author / byline to a modern page (immediately below the title)
/// <summary>
/// Sets the Author Byline for a modern page
/// </summary>
/// <remarks>
/// While there is a _AuthorByline field on the page list item and an AuthorBylineId and AuthorByline properties on the ClientSidePage,
/// these currently cannot be used to set the author byline. For that we have to use LayoutWebpartsContent on the list item.
/// </remarks>
/// <param name="context"></param>
/// <param name="page"></param>
/// <param name="userName"></param>
#Definition of the function that allows to enable a SPO Feature
function Enable-SPOFeature
{
param ($sSiteColUrl,$sUserName,$sPassword,$sFeatureGuid)
try
{
#Adding the Client OM Assemblies
#TODO - copy assemblies to the folder specified below
Add-Type -Path "C:\Temp\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Temp\Microsoft.SharePoint.Client.Runtime.dll"
<#
.SYNOPSIS
Sets the system fields for a specific list/library item.
.DESCRIPTION
This will set the system fields (created, created by, modified, modified by)
for a specific list/library item.
Provide any or all of those system fields as a parameter and they will be set.
If no modified date is provided, the item keeps its current modified date.
@kliemohn
kliemohn / Delete-WorkflowHistoryItems.ps1
Created April 26, 2016 20:25
Deletes all workflow history list items from a specific workflow history list. Also deletes everything from the recycle bin. Note that this script has a bug where it continues after it should be done (infinite loop).
if ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null){
Add-PSSnapin -Name Microsoft.SharePoint.PowerShell
}
$url = "http://ccsdev/sites/psc2"
$site = New-Object Microsoft.SharePoint.SPSite($url)
$web = $site.OpenWeb()
try{
$list = $web.GetList("/sites/psc2/WorkflowHistory")
@kliemohn
kliemohn / DocAve Copy.ps1
Last active August 29, 2015 14:20
Copies sites from one SharePoint environment to another using DocAve 6 accessing the SharePoint environments remotely. Sets up the DocAve site groups, plans, and executes the plans as jobs.
Import-Module DocAveModule
function CreateCopyPlan($planName, $planDescription, $srcSitesGroupName, $destSitesGroupName, $srcSiteUrl, $destSiteUrl)
{
Write-Host "Creating copy plan $($planName)..."
$plan = Get-DAContentManagerBlankOnlinePlan
$plan.Name = $planName
$plan.Description = $planDescription
$plan.Action = "Merge"
@kliemohn
kliemohn / ParseDomains.ps1
Created March 6, 2015 16:23
Parses a file full of user name and user IDs and outputs only the domain names found.
# Parses display name w/ user IDs (e.g., "John Doe [mydomain\jdoe]") to get the domain name
# Handles multiple per line if separated by semicolons
# Input is the filename that contains the rows of display names with user IDs
# Outputs only the domain name (does not output duplicates for the same row)
$currentPath=Split-Path ((Get-Variable MyInvocation -Scope 0).Value).MyCommand.Path
$filename = Join-Path $currentPath $args[0]
foreach ($line in [System.IO.File]::ReadLines($filename)) {
$users = $line.ToLower().Split(';')
$domains = new-object System.Collections.ArrayList
foreach ($user in $users)
@kliemohn
kliemohn / Get-SPLogEventSMTP.ps1
Last active August 29, 2015 14:14
Find SharePoint ULS Logs with SMTP Errors
Get-SPLogEvent -StartTime "2/6/2015" |
?{ $_.Message -like "*Bad response from SMTP*" } |
ForEach-Object {
$_
}
@kliemohn
kliemohn / Get-SPLogEventWithUrl.ps1
Last active August 29, 2015 14:14
Finds SharePoint ULS logs with request URLs
<#
.SYNOPSIS
Gets SharePoint ULS logs along with the request URL given a set of criteria.
.DESCRIPTION
The request URL is not available on every ULS log entry. If you want the request
URL, this command can provide it. It basically finds the log entry or entries
based on the criteria provided and then looks back up to 2 minutes in the logs
for a "Name=" message with the same correlation. If if finds one, it provides
that message which contains the request URL.