-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Several utility scripts to do some common tasks in SharePoint: Deploy a WSP farm solution, extract all the WSPs in the farm, etc.
- Loading branch information
1 parent
dc54a65
commit 5be34ab
Showing
21 changed files
with
613 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
############################################################################################################################################ | ||
# This script allows to easily add new fields to an existing custom list in a SharePoint site | ||
# Required parameters: | ||
# ->$sSiteUrl: Url of the site containing the list to be extended. | ||
# ->$sListName: Name of the list to be extended with a new field. | ||
# ->$sViewName: Name of the list view where we want to include the new field. | ||
# ->$fieldDisplayName: Display name for the field to be added. | ||
# ->$fieldInternalName: Internal name for the field to be added. | ||
# ->$sfieldType: Field type (Text, Choice, ...) | ||
############################################################################################################################################ | ||
|
||
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) | ||
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Site Url | ||
$sSiteUrl = "http://<SiteUrl>" | ||
|
||
#Definition of the function that adds a field to an existing list | ||
function Add-FieldToList | ||
{ | ||
param ($sListName, $sViewName, $fieldDisplayName, $fieldInternalName, $sfieldType) | ||
try | ||
{ | ||
$spSite = Get-SPSite -Identity $sSiteUrl | ||
$spWeb = $spSite.OpenWeb() | ||
$lList=$spWeb.Lists[$sListName] | ||
# Comprobamos si la columna existe | ||
if($lList.Fields[$fieldDisplayName]){ | ||
Write-host "Deleting the column in the list..." | ||
$lList.Fields[$fieldDisplayName].Delete(); | ||
} | ||
|
||
#We check the field type is not null | ||
if($spFieldType -ne '') | ||
{ | ||
write-Host "Adding the field $fieldDisplayName in the list $sListName" -foregroundcolor blue | ||
|
||
#We add the field to the list | ||
$lList.Fields.Add($fieldInternalName,$sFieldType,$false) | ||
|
||
#We updte the field in the list with the Display Name | ||
$lList.Fields[$fieldInternalName].Title=$fieldDisplayName | ||
$lList.Fields[$fieldInternalName].Update() | ||
$lList.Update() | ||
|
||
#Adding the field to the desired list view | ||
$vView = $lList.Views[$sViewName] | ||
$vView.ViewFields.Add($fieldDisplayName) | ||
$vView.Update() | ||
} | ||
|
||
#Disposing SPSite and SPWeb objects | ||
$spWeb.Dispose() | ||
$spSite.Dispose() | ||
|
||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
#Calling the function | ||
Start-SPAssignment –Global | ||
Add-FieldToList -sListName "<ListName>" -sViewName "<ListView>" -fieldDisplayName "<FieldDisplayName>" -fieldInternalName "<FieldInternalName>" -sfieldType "<FieldType>" | ||
Stop-SPAssignment –Global | ||
|
||
Remove-PsSnapin Microsoft.SharePoint.PowerShell |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
############################################################################################################################################ | ||
# Script to change the default upload file size through the Client Side Object Model (CSOM) | ||
# Required Parameters: | ||
# ->$iFileSize: New upload file size throught CSOM. | ||
############################################################################################################################################ | ||
|
||
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) | ||
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Definition of the function that allows to change the default upload file size for CSOM | ||
function ChangeFileSizeCSOM([int]$iFileSize) | ||
{ | ||
try | ||
{ | ||
$spWS = [Microsoft.SharePoint.Administration.SPWebService]::ContentService | ||
Write-Host "Valor por defecto de carga de archivos con CSOM " $spWS.ClientRequestServiceSettings.MaxReceivedMessageSize -ForegroundColor Yellow | ||
Write-Host "Cambiando el tamaño de carga de archivos con CSOM a $iFileSize" -ForegroundColor Green | ||
$spWS.ClientRequestServiceSettings.MaxReceivedMessageSize = $iFileSize | ||
$spWS.ClientRequestServiceSettings.MaxParseMessageSize=$iFileSize | ||
$spWS.Update() | ||
} | ||
catch [System.Exception] | ||
{ | ||
Write-Host $_.Exception.ToString() -ForegroundColor Red | ||
} | ||
} | ||
|
||
Start-SPAssignment -Global | ||
ChangeFileSizeCSOM -iFileSize 5242880 | ||
Stop-SPAssignment -Global | ||
|
||
Remove-PsSnapin Microsoft.SharePoint.PowerShell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
############################################################################################################################################ | ||
# Script that allows to configure the SharePoint Developer Dashboard | ||
# Required Parameters: | ||
# ->$sDeveloperDashboardOption: Configuration level (On, Off) for the Developer Dashboard). | ||
############################################################################################################################################ | ||
|
||
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) | ||
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Definition of the function that configures the Developer Dashboard | ||
function Configure-DeveloperDashboard | ||
{ | ||
param ($sDeveloperDashboardOption) | ||
try | ||
{ | ||
write-Host "Configuring the developer dashboard in mode $sDeveloperDashboardOption" -ForegroundColor Blue | ||
$svc=[Microsoft.SharePoint.Administration.SPWebService]::ContentService | ||
$ddsetting=$svc.DeveloperDashboardSettings | ||
$ddsetting.DisplayLevel=[Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::$sDeveloperDashboardOption | ||
$ddsetting.Update() | ||
Write-Host "Developer Dashboard configured in mode " $svc.DeveloperDashboardSettings.DisplayLevel -ForegroundColor Green | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Start-SPAssignment –Global | ||
#Calling the function | ||
Configure-DeveloperDashboard -sDeveloperDashboardOption Off | ||
Stop-SPAssignment –Global | ||
|
||
Remove-PsSnapin Microsoft.SharePoint.PowerShell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
############################################################################################################################################ | ||
# Script to configure outgoing e-mail in SharePoint | ||
# Required Parameters: | ||
# ->$sSMTPServer: SMTP Server. | ||
# ->$sFromEMail: From Address. | ||
# ->$sReplyEMail: To Address. | ||
# ->$sChartSet: Character Set. | ||
############################################################################################################################################ | ||
|
||
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) | ||
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } | ||
|
||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Definition of the function that configures outgoing e-mail in SharePoint | ||
function Configure-OutGoingEMail | ||
{ | ||
param ($sSMTPServer,$sFromEMail,$sReplyEmail,$sCharSet) | ||
try | ||
{ | ||
$CAWebApp = Get-SPWebApplication -IncludeCentralAdministration | Where { $_.IsAdministrationWebApplication } | ||
$CAWebApp.UpdateMailSettings($sSMTPServer, $sFromEMail, $sReplyEmail, $sCharSet) | ||
write-host -f Blue "Outgoing e-mail configured" | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Start-SPAssignment –Global | ||
|
||
#Objetos necesarios | ||
$sSMTPServer='<SMTP_Server>' | ||
$sFromEMail='<From_EMail>' | ||
$sReplyEmail='<Reply_EMail>' | ||
$sChartSet=65001 | ||
|
||
#Llamada a la función | ||
Configure-OutGoingEMail -sSMTPServer $sSMTPServer -sFromEMail $sFromEMail -sReplyEmail $sReplyEmail -sCharSet $sChartSet | ||
|
||
Stop-SPAssignment –Global |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
############################################################################################################################################ | ||
# This script allows to enumerate all the sites users in a SharePoint farm | ||
# Required parameters: N/A | ||
############################################################################################################################################ | ||
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) | ||
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
$ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path | ||
|
||
function GetAllUsersInAFarm | ||
{ | ||
|
||
try | ||
{ | ||
$sPath = Get-Location | ||
$spSites = Get-SPSite | ||
|
||
foreach ($spSite in $spSites) { | ||
[array]$spUsers = $null | ||
$sSiteName = $spSite.RootWeb.Title | ||
$sFileLocation = $ScriptDir + "\" + "$path\$sSiteName" + "_Users.csv" | ||
write-host -foregroundcolor green "SharePoint Site Collection: "$spSite.RootWeb.Title "..." | ||
foreach ($spWeb in $spSite.AllWebs) | ||
{ | ||
write-host -foregroundcolor blue "--SharePoint Web Site:" $spWeb.Title "..." | ||
foreach ($spGroup in $spWeb.groups) | ||
{ | ||
write-host -foregroundcolor yellow "----SharePoint Group:"$spGroup.Name "..." | ||
foreach($spUser in $spGroup.users) | ||
{ | ||
$spUsers = new-object psobject | ||
$spUsers | add-member noteproperty -name "User" -value $spUser | ||
$spUsers | add-member noteproperty -name "Display Name" -value $spUser.DisplayName | ||
$spUsers | add-member noteproperty -name "Groups" -value $spGroup.name | ||
$spUsers | add-member noteproperty -name "Site Name" -value $spSite.RootWeb.Title | ||
$spUsers | add-member noteproperty -name "Site URL" -value $spSite.Url | ||
$spUsers | Add-Member NoteProperty -name "Web Name" -value $spWeb.Title | ||
$spUsers | add-member noteproperty -name "Web URL" -value $spWeb.Url | ||
$spAllUsers += $spUsers | ||
} | ||
} | ||
$spWeb.Dispose() | ||
} | ||
$spAllUsers | export-csv -path $sFileLocation -notype | ||
$spAllUserss = $null | ||
$spSite.Dispose() | ||
} | ||
|
||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Start-SPAssignment –Global | ||
#Calling the function | ||
GetAllUsersInAFarm | ||
Stop-SPAssignment –Global | ||
|
||
Remove-PsSnapin Microsoft.SharePoint.PowerShell |
38 changes: 38 additions & 0 deletions
38
SharePoint/Utils/PS_ExecuteTestSPContentDatabase_AllContenDBs.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
############################################################################################################################################ | ||
# Script that allows to execute the cmdlet Test-SPContentDatabase against all the Content Databases in a SharePoint farm | ||
# Required parameters: | ||
# -> $SServerInstance: Name of the server where content databases are living. | ||
############################################################################################################################################ | ||
|
||
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) | ||
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Function that allows to execute Test-SPContentDatabase agains all the Content Databases in a SharePoint Farm | ||
function Execute-TestContentDatabase | ||
{ | ||
param ($sServerInstance) | ||
try | ||
{ | ||
$spWebApps = Get-SPWebApplication -IncludeCentralAdministration | ||
foreach($spWebApp in $spWebApps) | ||
{ | ||
$ContentDatabases = $spWebApp.ContentDatabases | ||
foreach($ContentDatabase in $ContentDatabases) | ||
{ | ||
Test-SPContentDatabase –Name $ContentDatabase.Name -ServerInstance $sServerInstance -WebApplication $spWebApp.Url | ||
} | ||
} | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Start-SPAssignment –Global | ||
Execute-TestContentDatabase -sServerInstance "<Sever_Instance>" | ||
Stop-SPAssignment –Global | ||
|
||
Remove-PsSnapin Microsoft.SharePoint.PowerShell |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
############################################################################################################################################ | ||
# Get al the WSPs (Farm Solutions) stored in the SharePoint Global Solutions Catalog | ||
# Parámetros necesarios: N/A | ||
############################################################################################################################################ | ||
|
||
If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) | ||
{ Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } | ||
|
||
$host.Runspace.ThreadOptions = "ReuseThread" | ||
|
||
#Function that gets all the WSPs (Farm Solutions) stored in the farm | ||
function GetAllWSPs | ||
{ | ||
write-host "Started the process of extraction solutions in the global solutions catalog ...." -foregroundcolor yellow | ||
try | ||
{ | ||
$spSolutions = Get-SPSolution | ||
foreach($spSolution in $spSolutions) | ||
{ | ||
Write-Host "Extrayendo la solución $spSolution" -ForegroundColor Yellow | ||
$spSolutionFile=$spSolution.SolutionFile | ||
$spSolutionFile.SaveAs($ScriptDir + "\" + $spSolution.DisplayName) | ||
} | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Start-SPAssignment –Global | ||
$ScriptDir = Split-Path -parent $MyInvocation.MyCommand.Path | ||
GetAllWSPs | ||
Stop-SPAssignment –Global | ||
Remove-PsSnapin Microsoft.SharePoint.PowerShell |
Oops, something went wrong.