├── Add-BackConnectionHostNamesKey.ps1 ├── Add-SQLServerAlias.ps1 ├── Add-SharePointCertToStore.ps1 ├── Add-WebApplicationPolicy.ps1 ├── CODE_OF_CONDUCT.md ├── CleanUp-ContentDatabase.ps1 ├── Configure-Farm.ps1 ├── Delete-UnusedGroups.ps1 ├── Disable-AudienceTargetingOnList.ps1 ├── Enable-AudienceTargetingOnList.ps1 ├── Enable-BlobCache.ps1 ├── Get-CEWPWithScript.ps1 ├── Get-DocFromUnattachedContentDB.ps1 ├── Get-EventReceiver.ps1 ├── Get-ImageWithSize.ps1 ├── Get-ItemsAndPermissions.ps1 ├── Get-NavigationTermSets.ps1 ├── Get-SyncConnections.ps1 ├── Get-WebTemplateCount.ps1 ├── Join-Farm.ps1 ├── LICENSE ├── Logoff-DisconnectedSession.ps1 ├── README.md ├── Remove-SSRSExportFormats.ps1 ├── Replace-EventReceiver.ps1 ├── Replace-ListImageUrl.ps1 ├── Set-CSVDelimiterForSSRS.ps1 ├── Set-ServiceIdentityForSPService.ps1 ├── Set-UPNSuffix.ps1 ├── Test-SiteColCreation.ps1 └── Wakeup-Farm.ps1 /Add-BackConnectionHostNamesKey.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Creates a BackConnectionHostNames key in the registry. 4 | 5 | .DESCRIPTION 6 | Creates a BackConnectionHostNames key in the registry. 7 | 8 | .NOTES 9 | File Name: Add-BackConnectionHostNamesKey.ps1 10 | Author : Bart Kuppens - CTG Belgium 11 | Version : 1.0 12 | 13 | .PARAMETER HostNames 14 | Specifies the hostnames for the BackConnectionHostNames key as a comma-delimited list. 15 | 16 | .EXAMPLE 17 | PS > .\Add-BackConnectionHostNamesKey.ps1 -HostNames "intranet.ctgdemo.com,teamsites.ctgdemo.com" 18 | #> 19 | [CmdletBinding()] 20 | param( 21 | [parameter(Position=0,Mandatory=$false,ValueFromPipeline=$false)] 22 | [string]$HostNames 23 | ) 24 | 25 | 26 | [System.String[]]$AdditionalUrlsArray = $null 27 | if ($HostNames -ne $null -and $HostNames.Length -gt 0) 28 | { 29 | $AdditionalUrlsArray = $HostNames.Split(",") 30 | } 31 | 32 | [string]$path = "HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0\" 33 | [string]$name = "BackConnectionHostNames" 34 | 35 | if ((Get-ItemProperty -Path $path -Name $name -ea silentlycontinue) -eq $null) 36 | { 37 | New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa\MSV1_0 -Name “BackConnectionHostNames” -Value "" -PropertyType multistring 38 | } 39 | else 40 | { 41 | Write-Output "BackConnectionHostNames already exists!" 42 | [string]$currentvalue = (Get-Item "$path").GetValue("$name") 43 | [System.String[]]$ExistingValues = "$currentvalue".Split() 44 | ForEach ($currentAlias in $ExistingValues) 45 | { 46 | if ($currentAlias) 47 | { 48 | if ($newAlias) 49 | { 50 | If($ArrayNewUrls -notcontains $currentAlias) 51 | { 52 | $newAlias = $newAlias+" "+$currentAlias 53 | } 54 | } 55 | Else 56 | { 57 | $newAlias = $currentAlias 58 | } 59 | } 60 | [System.String[]]$ArrayNewUrls = "$newAlias".Split() 61 | } 62 | ForEach ($addAlias in $ArrayAdditionalUrls) 63 | { 64 | If ($ExistingValues -notcontains $addAlias) 65 | { 66 | $newAlias = $newAlias+" "+$AddAlias 67 | } 68 | } 69 | } 70 | 71 | $newAlias = $newAlias.Trim() 72 | [System.String[]]$ArrayNewUrls = "$newAlias".Split() 73 | 74 | Set-ItemProperty -Path $path -Name $name -Value ([string[]]$ArrayNewUrls) -------------------------------------------------------------------------------- /Add-SQLServerAlias.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Adds a SQL Server alias to a server. Defaults to local machine if not provided. 4 | 5 | .DESCRIPTION 6 | Adds a SQL Server alias to a server. Defaults to local machine if not provided. 7 | 8 | .NOTES 9 | File Name: Add-SQLServerAlias.ps1 10 | Author : Bart Kuppens 11 | Updates : BillRob 12 | Version : 3.0 13 | 14 | .PARAMETER Name 15 | Specifies the name of the alias. 16 | 17 | .PARAMETER SQLServerName 18 | Specifies the name of the SQL Server. 19 | 20 | .PARAMETER Port 21 | Specifies the port. 22 | 23 | .PARAMETER Machine 24 | Specifies the computer where the registry is located. 25 | 26 | .PARAMETER x64 27 | Specifies whether the alias should be created for 64 bit. 28 | 29 | .PARAMETER overrideIfExists 30 | Specifies whether, if exist, the value will be overridden. 31 | 32 | .EXAMPLE 33 | PS > Add-SQLServerAlias -Name "SHPDB" -SQLServerName "SRV-CTG-SQL01" -Port 1433 -Machine SRV-CTG-SHP01 -x64 34 | #> 35 | 36 | [CmdletBinding()] 37 | param( 38 | [parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true,HelpMessage="Specifies the name of the alias.")] 39 | [string]$Name, 40 | [parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the name of the SQL Server.")] 41 | [string]$SQLServerName, 42 | [parameter(Position=2,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the port.")] 43 | [string]$Port, 44 | [parameter(Position=3,Mandatory=$false,ValueFromPipeline=$false,HelpMessage="Specifies the computer where the registry is located.")] 45 | [string]$Machine, 46 | [parameter(Position=4,Mandatory=$false,ValueFromPipeline=$false,HelpMessage="Specifies whether the alias should be created for 64 bit.")] 47 | [switch]$x64, 48 | [parameter(Position=5,Mandatory=$false,ValueFromPipeline=$false,HelpMessage="Specifies whether, if exist, the value will be overridden.")] 49 | [switch]$overrideIfExists 50 | ) 51 | 52 | $parentKeyx86 = "SOFTWARE\\Microsoft\\MSSQLServer\\Client\\" 53 | $parentKeyx64 = "SOFTWARE\\Wow6432Node\\Microsoft\\MSSQLServer\\Client\\" 54 | 55 | $hive = "localmachine" 56 | if($x64.IsPresent) 57 | { 58 | $parentKey = $parentKeyx64 59 | } 60 | else 61 | { 62 | $parentKey = $parentKeyx86 63 | } 64 | 65 | $key = "ConnectTo" 66 | 67 | # If the $Machine parameter was not provided, use the local machine. 68 | if ($Machine -eq $null) 69 | { 70 | $Machine = $ENV:COMPUTERNAME 71 | } 72 | 73 | try 74 | { 75 | # Connect to the registry (also works for remote machines) 76 | $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]$hive, $machine) 77 | } 78 | catch 79 | { 80 | Write-Host "Unable to connect to the registry of machine '$machine'. Please verify that the remote registry service is running and that you have administrative access to that machine." 81 | break 82 | } 83 | 84 | # Open the key in the registry 85 | $subkey = $reg.OpenSubKey($parentKey + $key, $true) 86 | if ($subkey -eq $null) 87 | { 88 | # The key doesn't exist, open the parent key and create the subkey. 89 | $parentTemp = $reg.OpenSubKey($parentKey,$true) 90 | if ($parentTemp -eq $null) 91 | { 92 | Write-Host "Parent key not found in the registry of '$machine'. Please verify that the SQL Client Tools are installed." 93 | break 94 | } 95 | else 96 | { 97 | try 98 | { 99 | $parentTemp.CreateSubKey($key) >> $null 100 | } 101 | catch 102 | { 103 | Write-Host "Unable to create the key '$key' in '$parentKey' on machine '$machine'. Do you have administrative permissions?" 104 | break 105 | } 106 | $subkey = $reg.OpenSubKey($parentKey + $key, $true) 107 | } 108 | } 109 | 110 | $res = $subkey.GetValue($Name) 111 | if (!$res -or $overrideIfExists.IsPresent) 112 | { 113 | $subkey.SetValue($Name,"DBMSSOCN,$SQLServerName,$Port") 114 | if (!$res) 115 | { 116 | Write-Output "Alias '$Name' created successfully!" 117 | } 118 | else 119 | { 120 | Write-Output "Alias '$Name' updated successfully!" 121 | } 122 | 123 | } 124 | else 125 | { 126 | Write-Output "Alias '$Name' already exists, consider using overrideIfExists parameter" 127 | } 128 | $reg.Close() 129 | -------------------------------------------------------------------------------- /Add-SharePointCertToStore.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Adds the "SharePoint Root Authority' certificate to the Trusted Root CA on the local SharePoint server. 4 | 5 | .DESCRIPTION 6 | Adds the "SharePoint Root Authority' certificate to the Trusted Root CA on the local SharePoint server. 7 | 8 | .NOTES 9 | File Name: Add-SharePointCertToStore.ps1 10 | Author : Bart Kuppens 11 | Version : 1.0 12 | #> 13 | 14 | # Load the SharePoint PowerShell snapin if needed 15 | if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) 16 | { 17 | Add-PSSnapin Microsoft.SharePoint.PowerShell 18 | } 19 | 20 | $RootCert = (Get-SPCertificateAuthority).RootCertificate 21 | 22 | if ($RootCert -eq $null) 23 | { 24 | Write-Output "Unable to get the SharePoint Root Certificate! Halting execution." 25 | } 26 | else 27 | { 28 | [void][System.Reflection.Assembly]::LoadWithPartialName("System.Security") 29 | $store = get-item Cert:\LocalMachine\Root 30 | if ($store -ne $null) 31 | { 32 | $store.Open("ReadWrite") 33 | $store.Add($RootCert) 34 | $store.Close() 35 | } 36 | } -------------------------------------------------------------------------------- /Add-WebApplicationPolicy.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Sets the Object Caching accounts 4 | 5 | .DESCRIPTION 6 | Sets the 2 user accounts (Portal Super User and Portal Super Reader) for the Object Caching for a webapplication. 7 | Requires 2 existing domain accounts. 8 | 9 | .NOTES 10 | File Name: Add-WebApplicationPolicy.ps1 11 | Author : Bart Kuppens 12 | Version : 1.0 13 | 14 | .PARAMETER Webapplication 15 | Web application URL 16 | 17 | .PARAMETER Superuser 18 | Domain account for the Portal Super User in the format 'domain\username' 19 | 20 | .PARAMETER Superreader 21 | Domain account for the Portal Super Reader in the format 'domain\username' 22 | 23 | .EXAMPLE 24 | PS > .\Add-WebApplicationPolicy.ps1 -Webapplication http://intranet.westeros.local -Superuser westeros\superuser -Superreader westeros\superreader 25 | 26 | Description 27 | ----------- 28 | This script gives the ctgdemo\superuser account "Full Control" and the ctgdemo\superreader account "Full Read" permissions on the specified webapplication 29 | #> 30 | 31 | param( 32 | [parameter(Position=0,Mandatory=$true,ValueFromPipeline=$true)] 33 | [string]$Webapplication, 34 | [parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false)] 35 | [string]$Superuser, 36 | [parameter(Position=2,Mandatory=$true,ValueFromPipeline=$false)] 37 | [string]$Superreader 38 | ) 39 | 40 | # Load SharePoint snapin if needed 41 | if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) 42 | { 43 | Write-Host "Loading SharePoint cmdlets..." 44 | Add-PSSnapin Microsoft.SharePoint.PowerShell 45 | } 46 | 47 | # Validate parameters 48 | $webApp = Get-SPWebApplication $Webapplication 49 | if ($webApp -eq $null) 50 | { 51 | Write-Host "'$webapplication' is not a valid SharePoint webapplication" 52 | break 53 | } 54 | 55 | # Convert plain user names to Claims if the webapp uses Claims Based authentication 56 | if ($webApp.UseClaimsAuthentication) 57 | { 58 | $cpSUser = New-SPClaimsPrincipal -Identity $Superuser -IdentityType WindowsSamAccountName 59 | $Superuser = $cpSUser.ToEncodedString() 60 | $cpSReader = New-SPClaimsPrincipal -Identity $Superreader -IdentityType WindowsSamAccountName 61 | $Superreader = $cpSReader.ToEncodedString() 62 | } 63 | 64 | # Check if a Web Application Policy already exists for the Portal Super User Account 65 | $policy = $webApp.Policies | Where {$_.UserName.ToLower() -eq $Superuser.ToLower()} 66 | if ($policy -eq $null) 67 | { 68 | $zp = $webApp.ZonePolicies("Default") 69 | $policy = $zp.Add($Superuser, "Portal Super User Account") 70 | $fc = $webApp.PolicyRoles.GetSpecialRole("FullControl") 71 | $policy.PolicyRoleBindings.Add($fc) 72 | $webApp.Properties["portalsuperuseraccount"] = $Superuser 73 | $webApp.Update() 74 | } 75 | else 76 | { 77 | Write-Host "Policy for $Superuser already exists" 78 | } 79 | 80 | # Check if a Web Application Policy already exists for the Portal Super Reader Account 81 | $policy = $webApp.Policies | Where {$_.UserName.ToLower() -eq $Superreader.ToLower()} 82 | if ($policy -eq $null) 83 | { 84 | $zp = $webApp.ZonePolicies("Default") 85 | $policy = $zp.Add($Superreader, "Portal Super Reader Account") 86 | $fc = $webApp.PolicyRoles.GetSpecialRole("FullRead") 87 | $policy.PolicyRoleBindings.Add($fc) 88 | $webApp.Properties["portalsuperreaderaccount"] = $Superreader 89 | $webApp.Update() 90 | } 91 | else 92 | { 93 | Write-Host "Policy for $Superreader already exists" 94 | } -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at bart.kuppens@outlook.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CleanUp-ContentDatabase.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Cleanup site collection marked for deletion and perform a shrink 4 | 5 | .DESCRIPTION 6 | Cleanup site collection marked for deletion and perform a shrink. 7 | 8 | .NOTES 9 | File Name: CleanUp-ContentDatabase.ps1 10 | Author : Bart Kuppens 11 | Version : 1.0 12 | 13 | .PARAMETER WebApplication 14 | Specifies the URL of the webapplication where the cleanup has to be executed. 15 | 16 | .PARAMETER ContentDatabase 17 | Specifies the name of the content database which has to be cleaned. 18 | 19 | .EXAMPLE 20 | PS C:\> .\Cleanup-ContentDatabase.ps1 -WebApplication http://teamsites.westeros.local ContentDatabase "SHP_WST_Content_TeamSites" 21 | #> 22 | [CmdletBinding()] 23 | param( 24 | [parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false)] 25 | [string]$WebApplication, 26 | [parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false)] 27 | [string]$ContentDatabase 28 | ) 29 | cls 30 | # Load the SharePoint PowerShell snapin if needed 31 | if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) 32 | { 33 | Write-Output "Loading SharePoint Snap-in..." 34 | Add-PSSnapin Microsoft.SharePoint.PowerShell 35 | } 36 | 37 | # Check if the webapplication exists 38 | $webapp = Get-SPWebApplication $WebApplication -ErrorAction SilentlyContinue 39 | if ($webapp -eq $null) 40 | { 41 | Write-Host -ForegroundColor Red "Web application '$WebApplication' doesn't exist, halting execution!" 42 | break 43 | } 44 | 45 | # Check if the contentdatabase exists 46 | $contentdb = Get-SPContentDatabase -Identity $ContentDatabase -ErrorAction SilentlyContinue 47 | if ($contentdb -eq $null) 48 | { 49 | Write-Host -ForegroundColor Red "Content database '$ContentDatabase' doesn't exist, halting execution!" 50 | break 51 | } 52 | else 53 | { 54 | # Check if the content database is attached to the web application 55 | if ($contentdb.WebApplication -ne $webapp) 56 | { 57 | Write-Host -ForegroundColor Red "Content database '$ContentDatabase' is not attached to '$WebApplication', halting execution!" 58 | break 59 | } 60 | } 61 | 62 | # Start the Gradual Site Delete for the specified web application 63 | $start = (Get-Date).ToUniversalTime() 64 | $timerjob = Get-SPTimerJob -Identity "job-site-deletion" -WebApplication $webapp 65 | Write-Host "Starting 'Gradual Site Delete' for $webApplication..." 66 | Start-SPTimerJob -Identity $timerjob 67 | 68 | # Wait for the job to complete 69 | Write-Host -NoNewLine "Waiting for job completion on database $ContentDatabase..." 70 | $jobhistoryentries = $timerjob.HistoryEntries | ? {$_.DatabaseName -eq $ContentDatabase -and $_.EndTime -gt $start} 71 | while ($jobhistoryentries -eq $null) 72 | { 73 | Start-Sleep -Seconds 300 74 | $jobhistoryentries = $timerjob.HistoryEntries | ? {$_.DatabaseName -eq $ContentDatabase -and $_.EndTime -gt $start} 75 | $status = $jobhistoryentries.Status 76 | } 77 | Write-Host " Completed with status : $status" 78 | $jobhistoryentries 79 | 80 | if ($status -eq [Microsoft.SharePoint.Administration.SPRunningJobStatus]::Succeeded) 81 | { 82 | Write-Host "Continuing with database Shrink..." 83 | [system.Reflection.Assembly]::LoadWithPartialName("Microsoft.SQLServer.Smo") >> $null 84 | $server = New-Object Microsoft.SqlServer.Management.Smo.Server $contentdb.Server 85 | $db = $server.Databases[$ContentDatabase] 86 | Write-Host "Current size (Mb) : $($db.Size)" 87 | Write-Host "Shrinking Step 1/2..." 88 | $db.Shrink(5,[Microsoft.SqlServer.Management.Smo.ShrinkMethod]::NoTruncate) 89 | $db.Refresh() 90 | Write-Host "Shrinking Step 2/2..." 91 | $db.Shrink(5,[Microsoft.SqlServer.Management.Smo.ShrinkMethod]::TruncateOnly) 92 | Write-Host "New size (Mb) : $($db.Size)" 93 | } 94 | else 95 | { 96 | Write-Host "The timer job failed. Halting execution!" 97 | break 98 | } 99 | 100 | -------------------------------------------------------------------------------- /Configure-Farm.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | SharePoint Farm Configuration. 4 | 5 | .DESCRIPTION 6 | Configures the local SharePoint farm: 7 | - Create the configuration database 8 | - Secure SharePoint resources 9 | - Install Services 10 | - Install Features 11 | - Provision Central Administration 12 | - Install Help Collection 13 | - Install Application Content 14 | 15 | .NOTES 16 | File Name: Configure-Farm.ps1 17 | Author : Bart Kuppens 18 | Version : 2.5 19 | 20 | .PARAMETER DatabaseServer 21 | Specifies the name of the server where the configuration database will be created. 22 | 23 | .PARAMETER ConfigDBName 24 | Specifies the name of the SharePoint Configuration database. 25 | 26 | .PARAMETER AdminContentDBName 27 | Specifies the name of the SharePoint Administration Content Database. 28 | 29 | .PARAMETER CentralAdminPort 30 | Specifies the number of the port for the Central Administration web application 31 | 32 | .PARAMETER AuthProvider 33 | Specifies the name of the authenticationprovider which will be used to create the 34 | Central Administration web application ("NTLM" or "KERBEROS") 35 | 36 | .PARAMETER FarmCredential 37 | Specifies the "domain\username" to be used as the Farm account. If omitted, you will be prompted to 38 | provide a valid domain account." 39 | 40 | .PARAMETER SP2010 41 | Specified when a new farm is created for SharePoint 2010. 42 | 43 | .PARAMETER SP2013 44 | Specified when a new farm is created for SharePoint 2013. 45 | 46 | .PARAMETER SP2016 47 | Specified when a new farm is created for SharePoint 2016. 48 | 49 | .PARAMETER IsDistributedCacheHost 50 | Specified when this server will be a Distributed Cache Host. 51 | For SP2016 farms, this parameter is only important when a "Custom" ServerRole is required and this local server needs to be 52 | a DistributedCache server. 53 | 54 | .PARAMETER ServerRole 55 | Specifies the role of the first server in the new farm. 56 | Possible values: Custom, WebFrontEnd, Application, DistributedCache, SingleServerFarm, Search, 57 | ApplicationWithSearch, WebFrontEndWithDistributedCache 58 | 59 | IMPORTANT!!! The roles 'ApplicationWithSearch' and 'WebFrontEndWithDistributionCache' are only valid 60 | when Feature Pack 1 has been installed (KB3127940 & KB3127942) 61 | 62 | .EXAMPLE 63 | PS > .\Configure-Farm.ps1 -DatabaseServer SHPDB -ConfigDBName SharePoint_Config_DB 64 | -AdminContentDBName SharePoint_Administration_DB -CentralAdminPort 1111 -AuthProvider NTLM -SP2010 65 | 66 | DESCRIPTION 67 | ----------- 68 | Will create a new SharePoint 2010 farm. 69 | 70 | .EXAMPLE 71 | PS > .\Configure-Farm.ps1 -DatabaseServer SHPDB -ConfigDBName SharePoint_Config_DB 72 | -AdminContentDBName SharePoint_Administration_DB -CentralAdminPort 1111 -AuthProvider NTLM -SP2013 -IsDistributedCacheHost 73 | 74 | DESCRIPTION 75 | ----------- 76 | Will create a new SharePoint 2013 farm and set the local server as a distributed cache host. 77 | 78 | .EXAMPLE 79 | PS > .\Configure-Farm.ps1 -DatabaseServer SHPDB -ConfigDBName SharePoint_Config_DB 80 | -AdminContentDBName SharePoint_Administration_DB -CentralAdminPort 1111 -AuthProvider NTLM -SP2016 -ServerRole Application 81 | 82 | DESCRIPTION 83 | ----------- 84 | Will create a new SharePoint 2016 farm and give the local server the "Application" server minrole. 85 | 86 | .EXAMPLE 87 | PS > .\Configure-Farm.ps1 -DatabaseServer SHPDB -ConfigDBName SharePoint_Config_DB 88 | -AdminContentDBName SharePoint_Administration_DB -CentralAdminPort 1111 -AuthProvider NTLM -SP2016 -ServerRole DistributedCache 89 | 90 | DESCRIPTION 91 | ----------- 92 | Will create a new SharePoint 2016 farm and give the local server the "DistributedCache" server minrole. 93 | 94 | #> 95 | [CmdletBinding()] 96 | param( 97 | [parameter(ParameterSetName="2010",Mandatory=$true,ValueFromPipeLine=$false)] 98 | [parameter(ParameterSetName="2013",Mandatory=$true,ValueFromPipeLine=$false)] 99 | [parameter(ParameterSetName="2016",Mandatory=$true,ValueFromPipeLine=$false)] 100 | [ValidateNotNullOrEmpty()] 101 | [string]$DatabaseServer, 102 | [parameter(ParameterSetName="2010",Mandatory=$true,ValueFromPipeLine=$false)] 103 | [parameter(ParameterSetName="2013",Mandatory=$true,ValueFromPipeLine=$false)] 104 | [parameter(ParameterSetName="2016",Mandatory=$true,ValueFromPipeLine=$false)] 105 | [ValidateNotNullOrEmpty()] 106 | [string]$ConfigDBName, 107 | [parameter(ParameterSetName="2010",Mandatory=$true,ValueFromPipeLine=$false)] 108 | [parameter(ParameterSetName="2013",Mandatory=$true,ValueFromPipeLine=$false)] 109 | [parameter(ParameterSetName="2016",Mandatory=$true,ValueFromPipeLine=$false)] 110 | [ValidateNotNullOrEmpty()] 111 | [string]$AdminContentDBName, 112 | [parameter(ParameterSetName="2010",Mandatory=$true,ValueFromPipeLine=$false)] 113 | [parameter(ParameterSetName="2013",Mandatory=$true,ValueFromPipeLine=$false)] 114 | [parameter(ParameterSetName="2016",Mandatory=$true,ValueFromPipeLine=$false)] 115 | [ValidateNotNullOrEmpty()] 116 | [string]$CentralAdminPort, 117 | [parameter(ParameterSetName="2010",Mandatory=$true,ValueFromPipeLine=$false)] 118 | [parameter(ParameterSetName="2013",Mandatory=$true,ValueFromPipeLine=$false)] 119 | [parameter(ParameterSetName="2016",Mandatory=$true,ValueFromPipeLine=$false)] 120 | [ValidateSet("NTLM","Kerberos")] 121 | [string]$AuthProvider, 122 | [parameter(ParameterSetName="2010",Mandatory=$false,ValueFromPipeLine=$false)] 123 | [parameter(ParameterSetName="2013",Mandatory=$false,ValueFromPipeLine=$false)] 124 | [parameter(ParameterSetName="2016",Mandatory=$false,ValueFromPipeLine=$false)] 125 | [PSCredential]$FarmCredential, 126 | [parameter(ParameterSetName="2010",Mandatory=$true,ValueFromPipeLine=$false)] 127 | [switch]$SP2010, 128 | [parameter(ParameterSetName="2013",Mandatory=$true,ValueFromPipeLine=$false)] 129 | [switch]$SP2013, 130 | [parameter(ParameterSetName="2016",Mandatory=$true,ValueFromPipeLine=$false)] 131 | [switch]$SP2016, 132 | [parameter(ParameterSetName="2013",Mandatory=$false,ValueFromPipeLine=$false)] 133 | [parameter(ParameterSetName="2016",Mandatory=$false,ValueFromPipeLine=$false)] 134 | [switch]$IsDistributedCacheHost, 135 | [parameter(ParameterSetName="2016",Mandatory=$true,ValueFromPipeLine=$false)] 136 | [ValidateSet("Custom","WebFrontEnd","Application","DistributedCache","SingleServerFarm","Search","ApplicationWithSearch","WebFrontEndWithDistributedCache")] 137 | [string]$ServerRole 138 | ) 139 | 140 | # Load the SharePoint PowerShell snapin if needed 141 | if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) 142 | { 143 | Add-PSSnapin Microsoft.SharePoint.PowerShell 144 | } 145 | 146 | # Get the Farm Credentials needed for the configuration 147 | if ($FarmCredential -eq $null) 148 | { 149 | $FarmCredential = Get-Credential -Message "Enter the Farm Account credentials" 150 | if ($FarmCredential -eq $null) 151 | { 152 | Write-Host -ForegroundColor Red "No Farm Credentials supplied, halting farm configuration!" 153 | break 154 | } 155 | } 156 | 157 | # Get the Passphrase for the configuration 158 | $Passphrase = Read-Host -AsSecureString "Enter the Farm Configuration passphrase" 159 | if ($Passphrase -eq $null) 160 | { 161 | Write-Host -ForegroundColor Red "No passphrase supplied, halting farm configuration!" 162 | break 163 | } 164 | 165 | # Start configuration 166 | Write-Progress -Activity "SharePoint Farm Configuration" -Status "Creating SharePoint configuration database" -PercentComplete 20 167 | if ($SP2016) 168 | { 169 | if ($IsDistributedCacheHost) 170 | { 171 | New-SPConfigurationDatabase -DatabaseName $ConfigDBName -DatabaseServer $DatabaseServer -AdministrationContentDatabaseName $AdminContentDBName -FarmCredentials $FarmCredential -Passphrase $Passphrase -LocalServerRole $ServerRole -ErrorVariable err 172 | } 173 | else 174 | { 175 | New-SPConfigurationDatabase -DatabaseName $ConfigDBName -DatabaseServer $DatabaseServer -AdministrationContentDatabaseName $AdminContentDBName -FarmCredentials $FarmCredential -Passphrase $Passphrase -LocalServerRole $ServerRole -SkipRegisterAsDistributedCacheHost -ErrorVariable err 176 | } 177 | } 178 | else 179 | { 180 | if ($SP2013) 181 | { 182 | if ($IsDistributedCacheHost) 183 | { 184 | New-SPConfigurationDatabase -DatabaseName $ConfigDBName -DatabaseServer $DatabaseServer -AdministrationContentDatabaseName $AdminContentDBName -FarmCredentials $FarmCredential -Passphrase $Passphrase -ErrorVariable err 185 | } 186 | else 187 | { 188 | New-SPConfigurationDatabase -DatabaseName $ConfigDBName -DatabaseServer $DatabaseServer -AdministrationContentDatabaseName $AdminContentDBName -FarmCredentials $FarmCredential -Passphrase $Passphrase -SkipRegisterAsDistributedCacheHost -ErrorVariable err 189 | } 190 | } 191 | else 192 | { 193 | New-SPConfigurationDatabase -DatabaseName $ConfigDBName -DatabaseServer $DatabaseServer -AdministrationContentDatabaseName $AdminContentDBName -FarmCredentials $FarmCredential -Passphrase $Passphrase -ErrorVariable err 194 | } 195 | } 196 | Write-Progress -Activity "SharePoint Farm Configuration" -Status "Verifying farm creation" -PercentComplete 30 197 | $spfarm = Get-SPFarm 198 | 199 | if ($spfarm -ne $null) 200 | { 201 | Write-Progress -Activity "SharePoint Farm Configuration" -Status "Securing SharePoint resources" -PercentComplete 40 202 | Initialize-SPResourceSecurity -ErrorVariable err 203 | 204 | Write-Progress -Activity "SharePoint Farm Configuration" -Status "Installing services" -PercentComplete 50 205 | Install-SPService -ErrorVariable err 206 | 207 | Write-Progress -Activity "SharePoint Farm Configuration" -Status "Installing features" -PercentComplete 60 208 | Install-SPFeature -AllExistingFeatures -ErrorVariable err > $null 209 | 210 | Write-Progress -Activity "SharePoint Farm Configuration" -Status "Provisioning Central Administration" -PercentComplete 70 211 | New-SPCentralAdministration -Port $CentralAdminPort -WindowsAuthProvider $AuthProvider -ErrorVariable err 212 | 213 | Write-Progress -Activity "SharePoint Farm Configuration" -Status "Installing Help" -PercentComplete 80 214 | Install-SPHelpCollection -All -ErrorVariable err 215 | 216 | Write-Progress -Activity "SharePoint Farm Configuration" -Status "Installing application content" -PercentComplete 90 217 | Install-SPApplicationContent -ErrorVariable err 218 | } 219 | else 220 | { 221 | Write-Error "ERROR: $err" 222 | } 223 | -------------------------------------------------------------------------------- /Delete-UnusedGroups.ps1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bkuppens/powershell/a245d14fd8b64c43095d81cc2f0406a40ea3a877/Delete-UnusedGroups.ps1 -------------------------------------------------------------------------------- /Disable-AudienceTargetingOnList.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Disables audience targeting on a SharePoint list or library. 4 | 5 | .DESCRIPTION 6 | Disables audience targeting on a SharePoint list or library. 7 | This will delete the audience targeting column from the list. All information contained in that column, will be lost! 8 | 9 | .NOTES 10 | File Name: Disable-AudienceTargetingOnList.ps1 11 | Author : Bart Kuppens 12 | Version : 1.0 13 | 14 | .PARAMETER Web 15 | Specifies the URL for the web where the library is located. 16 | 17 | .PARAMETER ListName 18 | Specifies the name of the list where you want to disable audience targeting. 19 | 20 | .EXAMPLE 21 | PS > .\Disable-AudienceTargeting.ps1 -Web http://teamsites.westeros.local -ListName Documents 22 | 23 | Description 24 | ----------- 25 | Disables audience targeting on the "Documents" library on http://teamsites.westeros.local 26 | #> 27 | [CmdletBinding()] 28 | param( 29 | [parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the URL for the web where the library is located.")] 30 | [string]$Web, 31 | [parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the name of the list where you want to enable audience targeting.")] 32 | [string]$ListName 33 | ) 34 | 35 | # Load the SharePoint PowerShell snapin if needed 36 | if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) 37 | { 38 | Write-Host "Loading the SharePoint PowerShell snapin..." 39 | Add-PSSnapin Microsoft.SharePoint.PowerShell 40 | } 41 | 42 | $SPWeb = Get-SPWeb $Web -EA SilentlyContinue 43 | if ($SPWeb -eq $null) 44 | { 45 | Write-Error "$Web is not a valid SharePoint Web" 46 | } 47 | else 48 | { 49 | Try 50 | { 51 | $fieldID = "61cbb965-1e04-4273-b658-eedaa662f48d" 52 | [Guid]$AudFieldID = New-Object System.Guid($fieldID) 53 | 54 | $list = $SPWeb.Lists[$ListName] 55 | if ($list -ne $null) 56 | { 57 | # Check if audience targeting is enabled on this list. 58 | $audField = $list.Fields[$AudFieldID] 59 | if ($audField -ne $null) 60 | { 61 | # It's enabled, disable it. 62 | $list.Fields.Delete($audField.InternalName); 63 | $list.Update() 64 | Write-Host -ForegroundColor Green "Audience targeting is succesfully disabled on '$ListName'" 65 | } 66 | else 67 | { 68 | Write-Host -ForegroundColor Yellow "Audience targeting is not enabled on '$ListName'" 69 | } 70 | } 71 | else 72 | { 73 | Write-Host "The list with the name $ListName was not found on $($SPWeb.Url)" 74 | } 75 | } 76 | catch 77 | { 78 | Write-Error $_.Exception 79 | } 80 | finally 81 | { 82 | $SPWeb.Dispose() 83 | } 84 | } -------------------------------------------------------------------------------- /Enable-AudienceTargetingOnList.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Enables audience targeting on a SharePoint list or library. 4 | 5 | .DESCRIPTION 6 | Enables audience targeting on a SharePoint list or library. 7 | This will add an extra column to all associated content types. 8 | This makes it important to do this AFTER you added the content 9 | types to the list or library. 10 | 11 | .NOTES 12 | File Name: Enable-AudienceTargetingOnList.ps1 13 | Author : Bart Kuppens 14 | Version : 1.0 15 | 16 | .PARAMETER Web 17 | Specifies the URL for the web where the library is located. 18 | 19 | .PARAMETER ListName 20 | Specifies the name of the list where you want to enable audience targeting. 21 | 22 | .EXAMPLE 23 | PS > .\Enable-AudienceTargeting.ps1 -Web http://teamsites.westeros.local -ListName Documents 24 | 25 | Description 26 | ----------- 27 | Enables audience targeting on the "Documents" library on http://teamsites.westeros.local. 28 | #> 29 | [CmdletBinding()] 30 | param( 31 | [parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the URL for the web where the library is located.")] 32 | [string]$Web, 33 | [parameter(Position=1,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the name of the list where you want to enable audience targeting.")] 34 | [string]$ListName 35 | ) 36 | 37 | # Load the SharePoint PowerShell snapin if needed 38 | if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) 39 | { 40 | Write-Host "Loading the SharePoint PowerShell snapin..." 41 | Add-PSSnapin Microsoft.SharePoint.PowerShell 42 | } 43 | 44 | $SPWeb = Get-SPWeb $Web -EA SilentlyContinue 45 | if ($SPWeb -eq $null) 46 | { 47 | Write-Error "$Web is not a valid SharePoint Web" 48 | } 49 | else 50 | { 51 | Try 52 | { 53 | $fieldID = "61cbb965-1e04-4273-b658-eedaa662f48d" 54 | [Guid]$AudFieldID = New-Object System.Guid($fieldID) 55 | 56 | $list = $SPWeb.Lists[$ListName] 57 | if ($list -ne $null) 58 | { 59 | # Check if audience targeting is already enabled on this list. 60 | $audField = $list.Fields[$AudFieldID] 61 | if ($audField -eq $null) 62 | { 63 | # Not yet enabled, enable it 64 | $xmlField = New-Object System.Xml.XmlDocument 65 | $field = $xmlField.CreateElement("Field") 66 | $field.SetAttribute("ID",$fieldID) 67 | $field.SetAttribute("Type","TargetTo") 68 | $field.SetAttribute("Name","TargetTo") 69 | $field.SetAttribute("DisplayName","Target Audiences") 70 | $field.SetAttribute("Required","FALSE") 71 | $list.Fields.AddFieldAsXml($field.OuterXml) >> $null 72 | $list.Update() 73 | Write-Host -ForegroundColor Green "Audience targeting is succesfully enabled on '$ListName'" 74 | } 75 | else 76 | { 77 | Write-Host -ForegroundColor Yellow "Audience targeting is already enabled on '$ListName'" 78 | } 79 | } 80 | else 81 | { 82 | Write-Host "The list with the name $ListName was not found on $($SPWeb.Url)" 83 | } 84 | } 85 | catch 86 | { 87 | Write-Error $_.Exception 88 | } 89 | finally 90 | { 91 | $SPWeb.Dispose() 92 | } 93 | } -------------------------------------------------------------------------------- /Enable-BlobCache.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Enables and configures the SharePoint BLOB Cache. 4 | 5 | .DESCRIPTION 6 | Enables and configures the SharePoint BLOB Cache. 7 | 8 | .NOTES 9 | File Name: Enable-BlobCache.ps1 10 | Author : Bart Kuppens 11 | Version : 2.0 12 | 13 | .PARAMETER Url 14 | Specifies the URL of the Web Application for which the BLOB cache should be enabled. 15 | 16 | .PARAMETER Location 17 | Specifies the location of the BLOB Cache. 18 | 19 | .EXAMPLE 20 | PS > .\Enable-BlobCache.ps1 -Url http://intranet.westeros.local -Location d:\BlobCache\Intranet 21 | 22 | Description 23 | ----------- 24 | This script enables the BLOB cache for the http://intranet.westeros.local web application and stores 25 | it under d:\blobcache\intranet 26 | #> 27 | param( 28 | [Parameter(Mandatory=$true, ValueFromPipeline=$false, Position=0)] 29 | [string]$Url, 30 | [Parameter(Mandatory=$true, ValueFromPipeline=$false, Position=1)] 31 | [string]$Location 32 | ) 33 | 34 | # Load the SharePoint PowerShell snapin if needed 35 | if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) 36 | { 37 | Add-PSSnapin Microsoft.SharePoint.PowerShell 38 | } 39 | 40 | $webApp = Get-SPWebApplication $Url 41 | $modifications = $webApp.WebConfigModifications | ? { $_.Owner -eq "BlobCacheMod" } 42 | if ($modifications.Count -ne $null -and $modifications.Count -gt 0) 43 | { 44 | Write-Host -ForegroundColor Yellow "Modifications have already been added!" 45 | break 46 | } 47 | 48 | # Enable Blob cache 49 | [Microsoft.SharePoint.Administration.SPWebConfigModification] $config1 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification 50 | $config1.Path = "configuration/SharePoint/BlobCache" 51 | $config1.Name = "enabled" 52 | $config1.Value = "true" 53 | $config1.Sequence = 0 54 | $config1.Owner = "BlobCacheMod" 55 | $config1.Type = 1 56 | 57 | # add max-age attribute 58 | [Microsoft.SharePoint.Administration.SPWebConfigModification] $config2 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification 59 | $config2.Path = "configuration/SharePoint/BlobCache" 60 | $config2.Name = "max-age" 61 | $config2.Value = "86400" 62 | $config2.Sequence = 0 63 | $config2.Owner = "BlobCacheMod" 64 | $config2.Type = 1 65 | 66 | # Set the location 67 | [Microsoft.SharePoint.Administration.SPWebConfigModification] $config3 = New-Object Microsoft.SharePoint.Administration.SPWebConfigModification 68 | $config3.Path = "configuration/SharePoint/BlobCache" 69 | $config3.Name = "location" 70 | $config3.Value = $Location 71 | $config3.Sequence = 0 72 | $config3.Owner = "BlobCacheMod" 73 | $config3.Type = 1 74 | 75 | #Add mods to webapp and apply to web.config 76 | $webApp.WebConfigModifications.Add($config1) 77 | $webApp.WebConfigModifications.Add($config2) 78 | $webApp.WebConfigModifications.Add($config3) 79 | $webApp.Update() 80 | $webApp.Parent.ApplyWebConfigModifications() -------------------------------------------------------------------------------- /Get-CEWPWithScript.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | .SYNOPSIS 3 | Returns a list of pages for a specific webapplication which contain CEWP's with script. 4 | 5 | .DESCRIPTION 6 | Returns a list of pages for a specific webapplication which contain CEWP's with script. 7 | 8 | .NOTES 9 | File Name: Get-CEWPWithScript.ps1 10 | Author : Bart Kuppens 11 | Version : 1.0 12 | 13 | .PARAMETER WebApplication 14 | Specifies the URL of the Web Application. 15 | 16 | .EXAMPLE 17 | PS > .\Get-CEWPWithScript.ps1 -WebApplication http://intranet.westeros.local 18 | 19 | Description 20 | ----------- 21 | Returns all Content Editor Web Parts which contains Javascript on the http://intranet.westeros.local webapplication 22 | #> 23 | [CmdletBinding()] 24 | param( 25 | [Parameter(Position=0,Mandatory=$true,ValueFromPipeline=$false,HelpMessage="Specifies the URL of the Web Application.")] 26 | [string]$WebApplication 27 | ) 28 | 29 | function Get-CEWP([string]$url) 30 | { 31 | $manager = $web.GetLimitedWebPartManager($url, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) 32 | $webParts = $manager.WebParts 33 | if ($webParts.Count -ne 0) 34 | { 35 | foreach ($webPart in $webParts) 36 | { 37 | if ($webPart.GetType() -eq [Microsoft.SharePoint.WebPartPages.ContentEditorWebPart]) 38 | { 39 | if ($webPart.ContentLink.Length -gt 0) 40 | { 41 | # Check file in ContentLink for script tags 42 | $file = $web.GetFile($webPart.ContentLink) 43 | $data = $file.OpenBinary() 44 | $encode = New-Object System.Text.ASCIIEncoding 45 | $contents = $encode.GetString($data) 46 | if ($contents.ToLower().Contains("