Tag Archives: SharePoint Administration
Delete ALL One-Time SPTimerJobs
One time SharePoint timer jobs can often get “stuck” and fail to execute. Clearing them all out manually in Central Admin is tedious. PowerShell below will remove all “One-time” jobs with a one liner. Cheers. ![]()
PowerShell Code
Get-SPTimerJob |? {$_.Schedule.GetType().ToString() -eq "Microsoft.SharePoint.SPOneTimeSchedule"} | % {$_.Delete()}Screenshot
References
VIDEO – Mini SQL Query
Review and demo of a great portable app named “Mini SQL Query” I use to verify SQL connectivity and run queries. Faster than full SQL Management Studio (SSMS). Portable app ZIP to download and double click EXE to run.
Video
References
Daily Front End Backup
The below PowerShell can be run once per day via Task Scheduler on just one machine in a SharePoint farm to backup front end configuration. Yes, SQL backups are wonderful and a must have for user data protection. However, front end backups are handy for restore scenarios like:
- IIS configuration
- IIS home folder
- WPS farm solutions
- 14/15 hive manual changes (yeah yeah … not best practice, but you have them too)
These front end artifacts might not be in a SQL full BAK. Also, having troubleshooting options on the front end helps SharePoint admins respond quickly to a recovery without having to wait for DBAs to first restore a database. Hope that helps. ![]()
Start-Transcript
Write-Host "Starting..."
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$dest = "d:\backuptest"
$day = Get-Date -Format "yyyy-MM-dd"
("iisconfig","inetpub","farmsol","hive","ipfs") |% {New-Item "$dest\$_-$day" -ItemType Directory -ErrorAction SilentlyContinue} | Out-Null
Write-Host " - IIS config"
Copy-Item "C:\windows\system32\inetsrv\config" "$dest\iisconfig-$day" -Recurse
Write-Host " - IIS home folder"
Copy-Item "C:\inetpub" "$dest\inetpub-$day" -Recurse
Write-Host " - SharePoint farm solutions"
Get-SPSolution |% {$s=$_.SolutionFile;$n=$s.Name;$s.SaveAs("$dest\farmsol-$day\$n")}
Write-Host " - SharePoint hive folder"
$major = (Get-SPFarm).BuildVersion.Major
Copy-Item "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\$major" "$dest\hive-$day" -Recurse
Write-Host " - InfoPath Forms Services"
Backup-SPFarm -Directory "$dest\ipfs-$day" -BackupMethod Full -Item "InfoPath Forms Services"
Write-Host " - Remove old folders"
$threshold = (Get-Date).AddDays(-2)
$files = Get-ChildItem $dest | Sort-Object LastWriteTime -Descending
$files | ?{ $_.LastWriteTime -lt $threshold } | Remove-Item -Force -Recurse
Write-Host "Operation completed successfully"
Stop-TranscriptMSODAL – Microsoft Online Services Diagnostics and Logging
With more people using Office365 every day, it can be helpful to have a few troubleshooting tools nearby. I had issues sending files over Lync IM and found this helpful download during my research. It verifies the local PC client configuration and is able to apply minor repairs for common configuration issues. Something to keep nearby as we all support more Office365 users.
http://support.microsoft.com/kb/2386684
- Desktop or Application sharing can’t connect in a Lync Online conference
https://technet.microsoft.com/en-us/library/hh852475.aspx
- Download MOSDAL (Microsoft Online Services Diagnostics and Logging) Support Toolkit
Backup-SPSite (with build version)
When backing up site collections I like to add the farm build version. Why? Helps me compare to other farms during restore and know if the patch level is too high/low. Also, when doing long term restores from months earlier it’s nice to know what the farm version was when the original backup was taken.
Just a small tip, but one I find handy for support.
$v=(Get-SPFarm).BuildVersion.ToString(); Backup-SPSite http://sp2010 -Path "c:\temp\sp2010.$v.site"
PowerShell – Notify all site users for outage / maintenance
The below PowerShell can be used to email all users of all site collections on your system. I find this helpful when planning maintenance outages to alert users of the down time, impact, and changes being performed.
Get-SPSite -Limit All |% {$url = $_.url;$_.RootWeb.SiteUsers | select UserLogin, DisplayName, Email, @{Name="SiteUrl";Expression={$url}}} | Export-Csv SiteUsers.csv
PowerShell – add security permission levels NoDelete AddOnly
Sometimes I need to enable Contributor site access but with safety limitations. “NoDelete” is the name I give for Contributor without Delete permissions. “AddOnly” is the name I give for Contributor without Delete or Edit permissions. Below is a quick PowerShell script “NoDeleteAddOnly.ps1” to create those permission levels.
UPDATE – Added SharePoint Online (CSOM)
# Credentials to connect to office 365 site collection url
$url = "https://tenant.sharepoint.com/sites/team"
$username = "spadmin@tenant.onmicrosoft.com"
$password = "pass@word1"
$secPassword = $password | ConvertTo-SecureString -AsPlainText -Force
# Load CSOM
Write-Host "Load CSOM libraries" -Foregroundcolor Black -Backgroundcolor Yellow
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
Write-Host "CSOM libraries loaded successfully" -Foregroundcolor black -Backgroundcolor Green
# Connect
Write-Host "Authenticate to SharePoint Online site collection $url and get ClientContext object" -Foregroundcolor black -Backgroundcolor yellow
$context = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $secPassword)
$Context.Credentials = $cred
$context.RequestTimeOut = 1000 * 60 * 10
$web = $context.Web
$site = $context.Site
$context.Load($web)
$context.Load($site)
try {
$context.ExecuteQuery()
Write-Host "Authenticated to SharePoint Online $url" -Foregroundcolor black -Backgroundcolor Green
}
catch {
Write-Host "Not able to authenticate to SharePoint Online $url - $($_.Exception.Message)" -Foregroundcolor black -Backgroundcolor Red
return
}
# Microsoft custom permission levels
# from https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.permissionkind.aspx
function CreateRoleDefinitions($permName, $permDescription, $clone, $addPermissionString, $removePermissionString) {
$roleDefinitionCol = $web.RoleDefinitions
$Context.Load($roleDefinitionCol)
$Context.ExecuteQuery()
# Check if the permission level is exists or not
$permExists = $roleDefinitionCol |? {$_.Name -eq $permName}
$clonePerm = $roleDefinitionCol |? {$_.Name -eq $clone}
Write-Host Creating Pemission level with the name $permName -Foregroundcolor black -Backgroundcolor Yellow
if (!$permExists) {
try {
$spRoleDef = New-Object Microsoft.SharePoint.Client.RoleDefinitionCreationInformation
$spBasePerm = New-Object Microsoft.SharePoint.Client.BasePermissions
if ($clonePerm) {
$spBasePerm = $clonePerm.BasePermissions
}
if ($addPermissionString) {
$addPermissionString.split(",") | % { $spBasePerm.Set($_) }
}
if ($removePermissionString) {
$removePermissionString.split(",") | % { $spBasePerm.Clear($_) }
}
$spRoleDef.Name = $permName
$spRoleDef.Description = $permDescription
$spRoleDef.BasePermissions = $spBasePerm
$web.RoleDefinitions.Add($spRoleDef)
$Context.ExecuteQuery()
Write-Host "Permission level with the name $permName created" -Foregroundcolor black -Backgroundcolor Green
}
catch {
Write-Host "There was an error creating Permission Level $permName : Error details $($_.Exception.Message)" -Foregroundcolor black -backgroundcolor Red
}
}
else {
Write-Host "Permission level with the name $permName already exists" -Foregroundcolor black -Backgroundcolor Red
}
}
# Create 4 Custom Permission Levels. Defined by removed permission strings.
CreateRoleDefinitions -permName "NoDelete" -permDescription "Contribute - without Delete" -clone "Contribute" -removePermissionString "DeleteListItems"
CreateRoleDefinitions -permName "AddOnly" -permDescription "Contribute - without Edit or Delete" -clone "Contribute" -removePermissionString "DeleteListItems,EditListItems"
CreateRoleDefinitions -permName "NoEdit" -permDescription "Contribute - without Edit" -clone "Contribute" -removePermissionString "EditListItems"
CreateRoleDefinitions -permName "EditOnly" -permDescription "Contribute - without Edit" -clone "Contribute" -removePermissionString "AddListItems,DeleteListItems"SharePoint On-Premise (SOM)
# #############################################################################
# NAME: NoDeleteAddOnly
#
# AUTHOR: Jeff Jones
# DATE: 09/13/2013
# EMAIL: spjeff@spjeff.com
# WEBSITE: www.spjeff.com
# TWiTTER: @spjeff
#
# COMMENT: This script creates two Custom Access levels for
# a given SharePoint URL.
#
# * NoDelete = Contribute without delete
# * AddOnly = Contribute without delete or edit
#
# REQUIRE: Permission to unlock account
# USAGE: .\NoDeleteAddOnly.ps1 http://sharepoint/sites/team
#
# #############################################################################
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$url
)
Write-Host "Opening $url ... " -NoNewLine
$web = Get-SPWeb $url
Write-Host "OK" -ForegroundColor Green
$nd = $web.RoleDefinitions |? {$_.Name -eq "NoDelete"}
if ($nd) {
Write-Host "Found NoDelete" -ForegroundColor Green
} else {
Write-Host "Missing NoDelete" -NoNewLine
Write-Host "Adding NoDelete ..." -NoNewLine
$noDeleteRole = New-Object "Microsoft.SharePoint.SPRoleDefinition"
$noDeleteRole.Name = "NoDelete"
$noDeleteRole.Description = "This group can view, add, and edit items, but cannot delete items"
$noDeleteRole.BasePermissions = "AddAndCustomizePages,AddDelPrivateWebParts,AddListItems,BrowseDirectories,BrowseUserInfo,CreateAlerts,EditListItems,EditMyUserInfo,ManagePersonalViews,Open,OpenItems,UpdatePersonalWebParts,UseClientIntegration,UseRemoteAPIs,ViewFormPages,ViewListItems,ViewPages,ViewVersions"
$web.RoleDefinitions.Add($noDeleteRole)
Write-Host "OK" -ForegroundColor Green
}
$ao = $web.RoleDefinitions |? {$_.Name -eq "AddOnly"}
if ($ao) {
Write-Host "Found AddOnly" -ForegroundColor Green
} else {
Write-Host "Missing AddOnly" -NoNewLine
Write-Host "Adding AddOnly ..." -NoNewLine
$addOnlyRole = New-Object "Microsoft.SharePoint.SPRoleDefinition"
$addOnlyRole.Name = "AddOnly"
$addOnlyRole.Description = "This group can view, add, and edit items, but cannot delete or edit items"
$addOnlyRole.BasePermissions = "AddAndCustomizePages,AddDelPrivateWebParts,AddListItems,BrowseDirectories,BrowseUserInfo,CreateAlerts,EditMyUserInfo,ManagePersonalViews,Open,OpenItems,UpdatePersonalWebParts,UseClientIntegration,UseRemoteAPIs,ViewFormPages,ViewListItems,ViewPages,ViewVersions"
$web.RoleDefinitions.Add($addOnlyRole)
Write-Host "OK" -ForegroundColor Green
}
