-
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.
Additional Utils Scripts added to the repository
- Loading branch information
1 parent
4e59d82
commit c706ae5
Showing
12 changed files
with
334 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,5 @@ | ||
Lastname,Firstname,EMail | ||
González Martín, Juan Carlos, [email protected] | ||
Hernández Marqués, Juan, [email protected] | ||
Movellán García, Rubén, [email protected] | ||
Martínez Lombo, Clara, [email protected] |
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,95 @@ | ||
############################################################################################################################################ | ||
# 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 funcion that changes de DisplayName for an existing column | ||
function Change-DisplayName | ||
{ | ||
param ($lList, $fieldDisplayName, $fieldInternalName) | ||
try | ||
{ | ||
$fieldToUpdate = $lList.Fields.GetFieldByInternalName($fieldInternalName) | ||
if ($fieldToUpdate -ne $null) { | ||
$fieldToUpdate.Title = $fieldDisplayName | ||
$xml = $fieldToUpdate.SchemaXml | ||
if ($xml -match "\s+DisplayName\s?=\s?`"([^`"]+)`"") { | ||
if ($matches[1] -ne $fieldToUpdate.Title) { | ||
$xml = $xml -replace $matches[0], " DisplayName=`"$($fieldToUpdate.Title)`"" | ||
$fieldToUpdate.SchemaXml = $xml | ||
} | ||
} | ||
} | ||
$fieldToUpdate.Update() | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
#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() | ||
#Changing the DisplayName | ||
Change-DisplayName -lList $lList -fieldDisplayName $fieldDisplayName -fieldInternalName $fieldInternalName | ||
|
||
#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 |
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,51 @@ | ||
############################################################################################################################################ | ||
# Script that allows to backup/restore a Site Collection | ||
# Required Parameters: | ||
# ->$sSiteCollection: Site Collection where we are going to do the backup / restore | ||
# ->$sBackupPath: Path where the Backup is stored | ||
# ->$sOperationType: Operation Type (Backup or Restore) | ||
############################################################################################################################################ | ||
|
||
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 restores de deleted Site Collection | ||
function BackupRestoreSiteCollection | ||
{ | ||
param ($sSiteCollection,$sBackupPath,$sOperationType) | ||
try | ||
{ | ||
switch ($sOperationType) | ||
{ | ||
"Backup" { | ||
Write-Host "Doing the backup for $sSiteCollection !!" -ForegroundColor Blue | ||
Backup-SPSite -Identity $sSiteCollection -Path $sBackupPath -Force | ||
Write-Host "Backup for $sSiteCollection successfully completed!!" -ForegroundColor Blue | ||
|
||
} | ||
"Restore" { | ||
Write-Host "Doing the restore for $sSiteCollection" -ForegroundColor Blue | ||
Restore-SPSite -Identity $sSiteCollection -Path $sBackupPath -Force | ||
Write-Host "Restore for $sSiteCollection successfully completed!!" -ForegroundColor Blue | ||
} | ||
default { | ||
Write-Host "Requested Operation not valid!!" -ForegroundColor DarkBlue | ||
} | ||
} | ||
|
||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Start-SPAssignment –Global | ||
#Calling the function | ||
BackupRestoreSiteCollection -sSiteCollection "http://c4968397007/sites/Intranet/" -sBackupPath "C:\Backups\Intranet.bak" -sOperationType "Restore" | ||
|
||
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,50 @@ | ||
############################################################################################################################################ | ||
# Script that allows to backup/restore all the WSPs in a Farm | ||
# Required Parameters: | ||
# ->$sSiteCollection: Site Collection where we are going to do the backup / restore | ||
# ->$sBackupPath: Path where the Backup is stored | ||
# ->$sOperationType: Operation Type (Backup or Restore) | ||
############################################################################################################################################ | ||
|
||
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 backup/restore all the WSPs in a farm! | ||
function BackupRestoreSiteCollection | ||
{ | ||
param ($sItem,$sBackupPath,$sOperationType) | ||
try | ||
{ | ||
switch ($sOperationType) | ||
{ | ||
"Backup" { | ||
Write-Host "Doing the backup for the item $sItem !!" -ForegroundColor Blue | ||
Backup-SPFarm -BackupMethod Full -Directory $sBackupPath -Item $sItem | ||
Write-Host "Backup for the item $sItem successfully completed!!" -ForegroundColor Blue | ||
|
||
} | ||
"Restore" { | ||
Write-Host "Doing the restore for the item $sItem" -ForegroundColor Blue | ||
Restore-SPFarm -RestoreMethod Overwrite -Directory $sBackupPath -Item $sItem -Percentage 10 -RestoreThreads 5 -Force | ||
Write-Host "Restore for the item $sItem successfully completed!!" -ForegroundColor Blue | ||
} | ||
default { | ||
Write-Host "Requested Operation not valid!!" -ForegroundColor DarkBlue | ||
} | ||
} | ||
|
||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Start-SPAssignment –Global | ||
#Calling the function | ||
BackupRestoreSiteCollection -sItem "farm\solutions" -sBackupPath "\\C4968397007\Backups\WSPs" -sOperationType "Restore" | ||
Stop-SPAssignment –Global | ||
|
||
Remove-PSSnapin Microsoft.SharePoint.PowerShell |
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,36 @@ | ||
############################################################################################################################################ | ||
# Script that allows to do an snapshot of SharePoint Content Database | ||
# Required Parameters: | ||
# ->$sSiteUrl: Site Url to get the Content DB | ||
############################################################################################################################################ | ||
|
||
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 performs the Content Database Snapshot | ||
function DoContentDBSnapShot | ||
{ | ||
param ($sSiteUrl) | ||
try | ||
{ | ||
Write-Host "Doing the Snapshot for $sWebApplication !!" -ForegroundColor Blue | ||
$sContentDB=Get-SPContentDatabase -Site $sSiteUrl | ||
$sContentDB.Snapshots.CreateSnapshot() | ||
Write-Host "Snapshot for $sWebApplication successfully completed!!" -ForegroundColor Blue | ||
|
||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Start-SPAssignment –Global | ||
#Calling the function | ||
DoContentDBSnapshot -sSiteUrl "http://<Site_Url>" | ||
|
||
Stop-SPAssignment –Global | ||
|
||
Remove-PSSnapin Microsoft.SharePoint.PowerShell |
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,35 @@ | ||
############################################################################################################################################ | ||
# Script that allows to import a Theasurus file definition to be used by the search engine. | ||
# Required Parameters: | ||
# ->$sTheasurusFilePath: Theasurus File Path | ||
############################################################################################################################################ | ||
|
||
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 imports the theasurus file | ||
function Import-TheasurusFIle | ||
{ | ||
param ($sTheasurusFilePath) | ||
try | ||
{ | ||
$searchApp = Get-SPEnterpriseSearchServiceApplication | ||
Import-SPEnterpriseSearchThesaurus -SearchApplication $searchApp -Filename $sTheasurusFilePath | ||
Write-Host "Theasurus file $sTheasurusFilePath imported successfully!" -ForegroundColor Blue | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
|
||
Start-SPAssignment –Global | ||
$sTheasurusFilePath="\\C4968397007\Demos\Formacion SP Avanzada\Busquedas\Sample_Thesaurus.csv" | ||
|
||
Import-TheasurusFIle -sTheasurusFilePath $sTheasurusFilePath | ||
Stop-SPAssignment –Global | ||
|
||
Remove-PSSnapin Microsoft.SharePoint.PowerShell |
Binary file not shown.
Binary file not shown.
55 changes: 55 additions & 0 deletions
55
SharePoint/Utils/PS_ReadOnly_ManteninanceMode_SiteCollection.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,55 @@ | ||
############################################################################################################################################ | ||
# This script allows to play with ReadOnly and ManteinanceMode properties at the Site Collection Level | ||
# Required Parameters: | ||
# ->$sSiteCollection: Site Collection where we are going to do the backup / restore. | ||
# ->$sOperationType: Operation Type (Read / Modify properties). | ||
# ->$sReadOnlyMode: Read Only mode for the ReadOnly property. | ||
############################################################################################################################################ | ||
|
||
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 restores de deleted Site Collection | ||
function ReadModify-SPSiteProperties | ||
{ | ||
param ($sSiteCollection,$sOperationType,$sReadOnlyMode) | ||
try | ||
{ | ||
$spSite=Get-SPSite -Identity $sSiteCollection | ||
|
||
#Operation Type | ||
switch ($sOperationType) | ||
{ | ||
"Read" { | ||
Write-Host "Reading $sSiteCollection values for ReadOnly & ManteinanceMode properties!!" -ForegroundColor Green | ||
Write-Host "Value for ReadOnly property: " $spSite.ReadOnly -ForegroundColor Green | ||
Write-Host "Value for ManteinanceMode property: " $spSite.MaintenanceMode -ForegroundColor Green | ||
} | ||
"Modify" { | ||
Write-Host "Modifiyng ReadOnly property in $sSiteCollection to $sReadOnlyMode" -ForegroundColor Green | ||
$spSite.ReadOnly=$sReadOnlyMode | ||
Write-Host "Value for ReadOnly property: " $spSite.ReadOnly -ForegroundColor Green | ||
} | ||
default { | ||
Write-Host "Requested Operation not valid!!" -ForegroundColor Green | ||
} | ||
} | ||
|
||
$spSite.Dispose() | ||
} | ||
catch [System.Exception] | ||
{ | ||
write-host -f red $_.Exception.ToString() | ||
} | ||
} | ||
|
||
Start-SPAssignment –Global | ||
#Calling the function | ||
ReadModify-SPSiteProperties -sSiteCollection "http://c4968397007:90" -sOperationType "Read" | ||
ReadModify-SPSiteProperties -sSiteCollection "http://c4968397007:90" -sOperationType "Modify" -sReadOnlyMode $false | ||
ReadModify-SPSiteProperties -sSiteCollection "http://c4968397007:90" -sOperationType "Read" | ||
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,7 @@ | ||
Key,Synonym,Language | ||
IE,Internet Explorer,es | ||
Internet Explorer,IE,es | ||
ONU,Naciones Unidas,es | ||
Naciones Unidas,ONU,es | ||
BAM,billing and account management,en | ||
billing and account management, en |