Skip to content

Instantly share code, notes, and snippets.

@nlarkin
nlarkin / Sharepoint_Report_Execution_History.sql
Created January 6, 2016 20:25
Get Sharepoint Report Execution History
Use ReportServer
Select e.*,
CASE(e.RequestType)
WHEN 0 THEN 'Interactive'
WHEN 1 THEN 'Subscription'
WHEN 2 THEN 'Refresh Cache'
ELSE 'Unknown'
END as ExecutionType
from ExecutionLogStorage e join Catalog c on e.ReportID = c.ItemID
@nlarkin
nlarkin / gettaxonomyterm.ps1
Created August 27, 2013 18:50
Powershell function for Sharepoint 2010 to get a taxonomy term using a spsite object, a field name and label. In this scenario we pass back the label / value pair however you can easily modify to return the term object.
Function GetTaxonomyTerm($spsite, $field, $label)
{
Write-Host "Getting term for $($label)..."
$taxonomySession = Get-SPTaxonomySession -Site $spsite
$taxonomyField = $spsite.RootWeb.Fields.GetField($field)
$termStoreID = $taxonomyField.SspId
$termStore = $taxonomySession.TermStores[$termStoreID]
$termsetID = $taxonomyField.TermSetId
@nlarkin
nlarkin / List Items within timespan.ps1
Created June 11, 2013 20:28
Powershell SPQuery to get documents created / modified within a specified time period (1 day in this case).
#Get SPWeb and Our List we are targeting.
$web = Get-SPWeb "http://spweburl"
$list = $web.Lists["List Name"]
#Build Query
$spQuery = New-Object Microsoft.SharePoint.SPQuery
#CAML Query Using a DateTime Value and and Offset of Today
$query = '<Where><Geq><FieldRef Name="Last_x0020_Modified" /><Value Type="DateTime"><Today OffsetDays="-1" /></Value></Geq></Where>'
$spQuery.ViewAttributes = "Scope = 'Recursive'"
$spQuery.Query = $query
@nlarkin
nlarkin / Delete List Items.ps1
Created May 30, 2013 18:54
Delete All List Items in a sharepoint list.
$w = Get-SPWeb http://spweburlhere
$l = $w.Lists["List Name Here"]
$c = $l.Items
$c | % {$l.GetItemById($_.ID).Delete()}
@nlarkin
nlarkin / ListAvailableWebTemplates.ps1
Created May 9, 2013 12:42
Sharepoint 2010 Powershell script to display list of currently available web templates for a given spweb object.
$url = “http://spweburl”
$spweb= Get-SPWeb $url
$templates= $site.GetAvailableWebTemplates($spweb.RegionalSettings.LocaleId)
$templates | Select Name, Title | Sort Title | Format-Table
$spweb.Dispose()
@nlarkin
nlarkin / ForceUnlock.ps1
Created March 25, 2013 13:51
Powershell Script to force a undocheckout of a specified document using the bypasslocks method.
cls
$error.Clear()
##################################################################################################
# Load SharePoint Snapin
##################################################################################################
$snap = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snap -eq $null) {
Write-Host "Loading Powershell Snapin..." -ForegroundColor Yellow
Add-PSSnapin Microsoft.SharePoint.Powershell
@nlarkin
nlarkin / GetListFields.ps1
Created March 12, 2013 16:09
Quick Powershell Script that will get available fields within a Sharepoint list.
#Enter web url
$web = Get-SPWeb "http://sharepointsite.com/"
#Enter Name of the list
$list = $web.Lists["Documents"]
$list.Fields | Select Title, InternalName | sort InternalName | out-file C:\internalfields.txt
@nlarkin
nlarkin / UpdateSiteAlertTimes.ps1
Created March 1, 2013 20:39
This is a powershell script that will update all the times for alerts within a specified Sharepoint Site. You must change the url and time to match your needs.
cls
$error.Clear()
##################################################################################################
# Load SharePoint Snapin
##################################################################################################
$snap = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snap -eq $null) {
Write-Host "Loading Powershell Snapin..." -ForegroundColor Yellow
Add-PSSnapin Microsoft.SharePoint.Powershell
@nlarkin
nlarkin / Site Alerts Export.ps1
Created March 1, 2013 19:54
Powershell script with cycle through all available Sharepoint sites and export the alerts to a .csv file. Requires person executing to change the site url prior to running the script. Should be run from regular powershell window.
cls
$error.Clear()
##################################################################################################
# Load SharePoint Snapin
##################################################################################################
$snap = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snap -eq $null) {
Write-Host "Loading Powershell Snapin..." -ForegroundColor Yellow
Add-PSSnapin Microsoft.SharePoint.Powershell
$xmlpath = "C:\PowershellConfig\Config.xml"
[xml]$userfile = Get-Content $xmlpath
$sitecollection = $userfile.Root.SiteCollection.URL
$path = $userfile.Root.DefaultPath