I'm trying to achieve a full User Profile setup for SharePoint 2010 using PowerShell, including the creation of the Active Directory connection.
My PowerShell source code comes mainly from here.
// define naming contexts
$context1 = new-object UserProfiles.DirectoryServiceNamingContext(
$distinguishedName,
$domainName,
$isDomain: #> $false,
$partitionId,
$containersIncluded,
$containersExcluded,
$preferredDomainControllers,
$useOnlyPreferredDomainControllers,
$isConfigurationNamingContext)
// creating the list of naming context
$listOfNamingContext.Add($context1);
$listOfNamingContext.Add(...);
// then create the connection
$serviceContext = Get-SPServiceContext // can be seen in the url given above
$configManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($serviceContext)
if($configManager.ConnectionManager.Contains($connectionName) -eq $false)
{
$configManager.ConnectionManager.AddActiveDirectoryConnection(
[Microsoft.Office.Server.UserProfiles.ConnectionType]::ActiveDirectory,
$connectionName, $domainName, <# useSSL: #> $false,
$userDomain, $userName, $password,
<# namingContexts #> $listOfNamingContext,
<# spsClaimProviderTypeValue: #> $null,
<# spsClaimProviderIdValue: #> $null)
}
Everything works fine except that run profiles for this connection are not created. Is this normal? When I create the same connection through SharePoint Central Admin, run profiles are created as in the following screenshot:
Do I need to create them programmaticaly or is there a problem? I've created one manually and the management agent works. And if I need to create them manually, how do I do this?