powershell Sharepoint Powershell Snippets

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell Sharepoint Powershell Snippets相关的知识,希望对你有一定的参考价值。

$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()
[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);
}
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
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)
}
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
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))

以上是关于powershell Sharepoint Powershell Snippets的主要内容,如果未能解决你的问题,请参考以下文章

powershell Powershell用于将Powershell与SharePoint 2007一起使用

powershell SharePoint Powershell添加列表项

powershell Sharepoint Powershell Snippets

powershell 为SharePoint 2013创建SharePoint服务帐户(最低)

使用 Powershell 插入 Sharepoint 凭据

powershell SharePoint事件接收器powershell脚本