Skip to content

Instantly share code, notes, and snippets.

@ciphertxt
ciphertxt / SampleFunctionTemplate.ps1
Created March 26, 2013 11:42
PowerShell Advanced function template
function Function-Name {
<#
.Synopsis
The short function description.
.Description
The long function description
.Example
C:\PS>Function-Name -param "Param Value"
This example does something
@ciphertxt
ciphertxt / SetSPListWorkflowAssocationCleanup.ps1
Created March 26, 2013 11:44
Sets the AutoCleanupDays for all workflow associations (not with a content type) on a list.
# Sample Usage
# Set-SPListWorkflowAssocationCleanup -WebUrl "http://intranet" -ListName "Shared Documents" -CleanupDays 365 -ReportOnly:$false
function Set-SPListWorkflowAssocationCleanup {
    param (
        [string] $WebUrl = $(Read-Host -prompt "Enter a Url"),
        [string] $ListName = $(Read-Host -prompt "Enter a List Name"),
        [int32] $CleanupDays = $(Read-Host -prompt "Enter the number of Cleanup Days"),
        [switch] $ReportOnly = $true
        )       
@ciphertxt
ciphertxt / SetSPListContentTypeWorkflowAssocationCleanup.ps1
Created March 26, 2013 11:45
Sets the AutoCleanupDays for a given list and content type
# Sample Use
# Set-SPListContentTypeWorkflowAssocationCleanup -WebUrl "http://intranet" -ListName "Shared Documents" -ContentTypeName "Document Content Type" -CleanupDays 365 -ReportOnly:$false
function Set-SPListContentTypeWorkflowAssocationCleanup {
    param (
        [string] $WebUrl = $(Read-Host -prompt "Enter a Url"),
        [string] $ListName = $(Read-Host -prompt "Enter a List Name"),
        [string] $ContentTypeName = $(Read-Host -prompt "Enter a Content Type Name"),
        [int32] $CleanupDays = $(Read-Host -prompt "Enter the number of Cleanup Days"),
        [switch] $ReportOnly = $true
@ciphertxt
ciphertxt / SetSPUIVersion.ps1
Created March 26, 2013 11:47
Sets the UIVersion to v3 or v4 for all sites in a given database
function Set-SPUIVersion(
    [string]$dbName = $(Read-Host -prompt "Content Database Name"),
    [int32]$uiVersion = $(Read-Host -prompt "UI Version"))
    {
    $db = Get-SPContentDatabase $dbName
 
    foreach ($s in $db.Sites) {
        foreach ($w in $s.AllWebs) {
            $w.UIversion = $uiVersion;
            switch ($uiVersion) {
@ciphertxt
ciphertxt / GetSPFarmSolutions.ps1
Created March 26, 2013 11:48
Saves all farm solutions to the specified directory
function Get-SPFarmSolutions {
    param (
        [string] $directory = $(Read-Host -prompt "Enter a directory (use ""."" for current dir)")
    )
 
    if ($directory.Length -lt 2) {
        $directory = [string]$pwd + "\\";
    }
 
    $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local;
@ciphertxt
ciphertxt / PSConfig.cmd
Created March 26, 2013 11:49
PSConfig cmd line for after applying a patch
psconfig -cmd upgrade -inplace b2b -force -cmd applicationcontent -install -cmd installfeatures
@ciphertxt
ciphertxt / PopulateUserInformationList.ps1
Created March 26, 2013 11:50
Adds all users in the UPA to a given site collection. Handy for pre-populating a User Information List
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
# Enter your SharePoint site URL here...
$site = new-object Microsoft.SharePoint.SPSite("http://intranet");
$web = Get-SPWeb "http://intranet";
$ServiceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($site);
@ciphertxt
ciphertxt / CreateUserProfile.ps1
Created March 26, 2013 11:50
Creates a new user profile in the UPA
Add-PSSnapin Microsoft.SharePoint.PowerShell
$siteUrl = "http://mycoolsite/"
$accountName = "MyAccountName"
$site = Get-SPSite $siteUrl
$context = Get-SPServiceContext($site)
$pm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
# If user profile doesn't exist create new one
@ciphertxt
ciphertxt / BackupWebConfig.ps1
Created March 26, 2013 11:52
Backup the web.config for a given web application
$webappName = “http://intranet.contoso.com”
$backupDir = “C:\backups”
Write-Host "Backing up $webappName web.config file…" -foreground Gray –nonewline
## Get the web application – by display name
$w = Get-SPWebApplication | where { $_.DisplayName -eq "$webappName"}
## Get the default (first) zone for the web app…
## You may wish to iterate through all the available zones
@ciphertxt
ciphertxt / DownloadSPC14.ps1
Created March 16, 2014 23:04
Downloads the SPC14 files with BITS instead of WebClient
[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
$rss = (new-object net.webclient)
$a = [xml]($rss.downloadstring("http://channel9.msdn.com/Events/SharePoint-Conference/2014/RSS/mp4high"))
$a.rss.channel.item | foreach {
$code = $_.comments.split("/") | select -last 1
$url = New-Object System.Uri($_.enclosure.url)
$file = $code + "-" + $_.creator + "-" + $_.title.Replace("'","").Replace("*","").Replace(":", "-").Replace("?", "").Replace("/", "-").Replace("<", "")