[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)
}