Tuesday, 24 May 2016

Using Windows Powershell Cmdlets with ULS Logging

ULS provides Windows PowerShell cmdlets for a number of operations, including:
  • Changing ULS configuration settings
  • Trace and Event Level throttling
  • Flushing current log and starting a new one
  • Querying and filtering Trace Logs
  • Merging Trace Logs from multiple machines
CmdLet Examples
Retrieves Diagnostic Configuration values.
Diagnostic Configuration
Allows setting Diagnostic Configuration values.
Diagnostic Configuration
Returns IDiagnosticsLevel2 objects or displays a list of diagnostics levels.
Trace Log and Event Log Throttling
Allows the user to set the trace and event level for a set of categories.
Trace Log and Event Log Throttling
Resets the trace and event levels back to their default values.
Trace Log and Event Log Throttling
Ends the current log file and starts a new one.
Log File Control
Reads/queries ULS trace logs.
Trace Log Querying and Filtering
Combines trace log files from all farm servers into a single file.
Trace Log Merging

Wednesday, 11 May 2016

Clean up SharePoint User Profile Store using PowerShell

There is a solution using PowerShell without compiled code. Using PowerShell everything what is available in the server object model is available. First of all two assemblies must be referenced.
These assemblies are:
Those assemblies could be referenced using System.Reflection and the rest of the script is quite simple SharePoint Development. So get a context object, open profile service application get all use and delete them.

# Load required Assemblies for SharePoint Server and User Profile

# Central Adminstration URL or any Web Application
$url = "http://mainframe:48248"
# Create a new Context Object
$contextWeb = New-Object Microsoft.SharePoint.SPSite("http://mainframe");

# 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 ) {
# Remove Profile

This script can be extended to delete only specific users from user profile information. At the end I was able to solve my problem. My User Profile was deleted and recreated on first access and due profile import. Everything worked fine.
In the old days you had to write some custom command line tool to address those batch update and deletion task. With the introduction of PowerShell to SharePoint any possible administrative task could be accomplished by just use scripting.