Created
December 11, 2014 11:10
-
-
Save ielcoro/57d861886fc51d78e7f8 to your computer and use it in GitHub Desktop.
Sharepoint Powershell Snippets
This file contains hidden or 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
$fieldName = "field" | |
$contentTypeId = New-Object Microsoft.Sharepoint.SPContentTypeId("0x010100629D00608F814DD6AC8A86903AEE72AA") | |
Add-PSSnapin Microsoft.Sharepoint.Powershell | |
$web = Get-SPWeb http://cun04 | |
$contentType = $web.ContentTypes | ? { $_.ID.IsParentOf($contentTypeId) } | |
$contentType.FieldLinks.Delete($fieldName) | |
$contentType.Update($true) | |
$web.Fields.Delete($fieldName) | |
$web.Update() |
This file contains hidden or 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
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server") | |
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles") | |
# Central Adminstration URL or any Web Application | |
$url = "http://cpdcun47:17001" | |
# Create a new Context Object | |
$contextWeb = New-Object Microsoft.SharePoint.SPSite("http://cpdcun47"); | |
# Get the right Service Context | |
$ServerContext = [Microsoft.Office.Server.ServerContext]::GetContext($contextWeb); | |
# create a new connection to the UserProfileManager | |
$UserProfileManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($ServerContext); | |
# Ger all User Profiles | |
$Profiles = $UserProfileManager.GetEnumerator(); | |
# Loop through user profile | |
foreach ($oUser in $Profiles ) { | |
$accountName = $oUser.item("AccountName"); | |
# Remove Profile | |
Write-Host "Eliminando Usuario $accountName" | |
$UserProfileManager.RemoveUserProfile($accountName); | |
} |
This file contains hidden or 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
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | |
function EnsureDirectory($exportFolderPath) | |
{ | |
if ( -not (Test-Path $exportFolderPath) ) {New-Item $exportFolderPath -Type Directory | Out-Null} | |
} | |
function ExportAllWebParts($siteUrl,$pageUrl,$exportFolderPath) | |
{ | |
$web = Get-SPWeb $siteUrl | |
$wpm = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared) | |
EnsureDirectory $exportFolderPath | |
foreach($wp in $wpm.WebParts) | |
{ | |
$wp.ExportMode="All"; | |
$exportPath = $exportFolderPath + "\" + $wp.Title + ".xml" | |
$xwTmp = new-object System.Xml.XmlTextWriter($exportPath,$null); | |
$xwTmp.Formatting = 1;#Indent | |
$wpm.ExportWebPart($wp, $xwTmp); | |
$xwTmp.Flush(); | |
$xwTmp.Close(); | |
} | |
} | |
ExportAllWebParts $args[0] $args[1] $args[2] | |
# I use this script as a file, ExportWebParts.ps1. The required arguments for this script should be: | |
#The site absolute URL | |
#The page site-relative URL | |
#The folder path for export | |
#example usage ./ExportWebParts.ps1 http://spdevel.portal.com/ Pages/default.aspx C:\temp\Export |
This file contains hidden or 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
Add-Type -AssemblyName "Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" | |
Add-Type -Path .\GestionExpedientes.dll -Verbose | |
$site = New-Object -TypeName Microsoft.Sharepoint.SPSite -ArgumentList "http://cpdcun47/sitios/PruebaPRO" | |
$site = [Microsoft.Sharepoint.SPSite] $site | |
$featureUpgrade = New-Object -TypeName Consultec.CUN.GestionExpedientes.Features.Expedientes.ExpedientesEventReceiver | |
$featurteDefinition = [Microsoft.SharePoint.Administration.SPFeatureDefinition] $site.WebApplication.Farm.FeatureDefinitions.Item([System.Guid]::Parse("0f0ad33c-5866-4dc9-9ef8-9e7d10286043")) | |
#Only retrieve static private method | |
$BindingFlags= [Reflection.BindingFlags] "Instance, NonPublic" | |
#Load method based on name | |
$PrivateMethod = $featureUpgrade.GetType().GetMethod("AplicarConfiguraciones", $bindingFlags) | |
#Invoke | |
$PrivateMethod.Invoke($featureUpgrade, @($site, $null)) |
This file contains hidden or 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
BEGIN { | |
$ErrorActionPreference = "Stop" | |
if ( $null -eq ([AppDomain]::CurrentDomain.GetAssemblies() |? { $_.FullName -eq "System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" }) ) { | |
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null | |
} | |
$publish = New-Object System.EnterpriseServices.Internal.Publish | |
} | |
PROCESS { | |
$assembly = $null | |
if ( $_ -is [string] ) { | |
$assembly = $_ | |
} elseif ( $_ -is [System.IO.FileInfo] ) { | |
$assembly = $_.FullName | |
} else { | |
throw ("The object type '{0}' is not supported." -f $_.GetType().FullName) | |
} |
This file contains hidden or 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
Add-PSSnapin Microsoft.Sharepoint.Powershell | |
Add-SPSolution -LiteralPath C:\Instalaciones\Soluciones\5.0.0.0\COB.SharePoint.Utilities.FeatureUpgradeKit.wsp | |
Install-SPSolution -Identity COB.SharePoint.Utilities.FeatureUpgradeKit.wsp -GACDeployment | |
Add-SPSolution -LiteralPath C:\Instalaciones\Soluciones\5.0.0.0\ListViewFilter.wsp | |
Install-SPSolution -Identity listviewfilter.wsp -GACDeployment -WebApplication http://cpdcun47 | |
Add-SPSolution -LiteralPath C:\Instalaciones\Soluciones\5.0.0.0\GestionExpedientes_4_0_0_0.wsp | |
Install-SPSolution -Identity gestionexpedientes_4_0_0_0.wsp -GACDeployment -WebApplication http://cpdcun47 | |
Update-SPSolution -Identity gestionexpedientes_4_0_0_0.wsp -LiteralPath C:\Instalaciones\Soluciones\5.0.0.0\GestionExpedientes_5_0_0_0.wsp -GACDeployment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment