Skip to content

Instantly share code, notes, and snippets.

@jjaramillo
Created June 9, 2015 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjaramillo/d69c02e66d13fae1a5e0 to your computer and use it in GitHub Desktop.
Save jjaramillo/d69c02e66d13fae1a5e0 to your computer and use it in GitHub Desktop.
Everyday poweshell scripts for sharepoint. Originally found on http://www.vrdmn.com/2012/10/everyday-powershell-scripts-for.html
#add indexes to a field on a list
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
function IndexField($fieldName, $spList)
{
$spField = $spList.Fields[$fieldName]
$spField.Indexed = $true
$spField.Update()
$spList.FieldIndexes.Add($spField)
$spList.Update()
Write-Host "$fieldName Indexed"
}
try
{
$SiteUrl = "http://spsa00:6000/"
$web = Get-SPWeb $SiteUrl
$spList = $web.Lists["Tasks"]
IndexField "Assigned To" $spList
IndexField "Status" $spList
$web.Dispose()
}
Catch [system.exception]
{
$error[0]
}
#clear cache
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$site = Get-SPSite "http://spsa00:7766/"
$cache = New-Object Microsoft.SharePoint.Publishing.SiteCacheSettingsWriter $site
$cache.SetFarmCacheFlushFlag()
$cache.Update()
Write-Host "Object Cache Cleared"
#Enable Developer Dashboard
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$ddb = [Microsoft.SharePoint.Administration.SPWebService]::ContentService.DeveloperDashboardSettings
#On, Off, OnDemand
$ddb.DisplayLevel = [Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::OnDemand
$ddb.RequiredPermissions = 'EmptyMask'
$ddb.TraceEnabled = $true
$ddb.Update()
Write-Host "Developer Dashboard Enabled"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment