Hi Guys,
Trying to figure this out. I am using the PSMA to control Lync identities, importation is OK, but it's not projecting and nor exporting data to lync. There's something missing?
Here the scripts:
IMPORT
param
(
$Username = "",
$Password = "",
$OperationType = "Full",
[bool] $UsePagedImport,
$PageSize
)
# these delta properties are used for delta searches in Active Directory. When this script is called
# with the Delta operation type, it will only return users objects where one of the specified
# attributes has changed since last import
$DeltaPropertiesToLoad = @( "distinguishedname", "mail", "homemdb", "objectguid", "isdeleted", "samaccountname", "oksecondarymail" )
# the MASchemaProperties are the properties that this script will return to FIM on objects found
$MASchemaProperties = @( "mail", "samaccountname", "oksecondarymail" )
$rootdse = [adsi] "LDAP://RootDSE"
$searchroot = $rootdse.defaultnamingcontext
$domain = new-object system.directoryservices.directoryentry "LDAP://$searchroot", $username, $password
$Searcher = new-object System.DirectoryServices.DirectorySearcher $Domain, "(&(objectClass=user)(objectCategory=person))", $DeltaPropertiesToLoad, 2
$searcher.tombstone = ($operationtype -match 'delta')
$searcher.cacheresults = $false
if ($OperationType -eq "Full" -or $RunStepCustomData -match '^$')
{
# reset the directory synchronization cookie for full imports (or no watermark)
$searcher.directorysynchronization = new-object system.directoryservices.directorysynchronization
}
else
{
# grab the watermark from last run and pass that to the searcher
$Cookie = [System.Convert]::FromBase64String($RunStepCustomData)
$SyncCookie = ,$Cookie # forcing it to be of type byte[]
$searcher.directorysynchronization = new-object system.directoryservices.directorysynchronization $synccookie
}
$results = $searcher.findall()
$results = $results | where { $_.psbase.path -match 'OU=USERS,DC=DOMAIN,DC=LOCAL$' }
if ( $results -ne $null )
{
foreach ($global:result in $results)
{
# we always add objectGuid and objectClass to all objects
$obj = @{}
$obj.id = ([guid] $result.psbase.properties.objectguid[0]).tobytearray()
$obj."[DN]" = $result.psbase.path -replace '^LDAP\://'
$obj.objectClass = "user"
if ( $result.Properties.Contains("isdeleted"))
{
# this is a deleted object, so we return a changeType of 'delete'; default changeType is 'Add'
$obj.changetype = "delete"
if ( $operationtype -ne 'full' )
{
$obj
}
}
else
{
# we need to get the directory entry to get the additional attributes since
# these are not available if we are running a delta import (DirSync) and
# they haven't changed. Using just the SearchResult would only get us
# the changed attributes on delta imports and we need more, oooh, so much more
$global:direntry = $result.getdirectoryentry()
# special handled attribute
$obj.'ismailboxenabled' = $direntry.properties.contains('homemdb')
# always add the objectguid and objectsid
$obj.objectguidstring = [string] ([guid] $result.psbase.properties.objectguid[0])
$obj.objectsidstring = [string] ( New-Object System.Security.Principal.SecurityIdentifier($DirEntry.Properties["objectSid"][0], 0) )
# add the attributes defined in the schema for this MA
$maschemaproperties | foreach-object `
{
write-debug $_
if ( $direntry.properties.$_ )
{
$obj.$_ = $direntry.properties[$_][0]
}
}
$obj
}
}
}
# grab the synchronization cookie value to use for next delta/watermark
# and put it in the $RunStepCustomData. It is important to mark the $RunStepCustomData
# as global, otherwise FIM cannot pick it up and delta's won't work correctly
$global:RunStepCustomData = [System.Convert]::ToBase64String($Searcher.DirectorySynchronization.GetDirectorySynchronizationCookie())
EXPORT
PARAM
(
$username = "",
$password = "",
$domain = ""
)
begin
{
function log( $message )
{
if ( $message )
{
write-debug $message
$message | out-file e:\logs\exchange-ps-export.log -append
}
}
function set-actioninfo($message)
{
if ( $message )
{
$global:actioninfo = $message
log -message $actioninfo
write-debug $actioninfo
}
else
{
$actioninfo = "general"
}
}
log -message "begin export"
$securepassword = convertto-securestring $password -asplaintext -force
$creds = new-object -typename system.management.automation.pscredential($username, $securepassword)
set-actioninfo "new-pssession"
$session = new-pssession -connectionuri ('https://SERVER.DOMAIN.LOCAL/OcsPowershell') -credential $creds -debug
import-pssession -session $session
}
process
{
log -message "-- start export entry --"
$identifier = $_."[Identifier]"
$anchor = $_."[Anchor]"
$dn = $_."[DN]"
$objecttype = $_."[ObjectType]"
$changedattrs = $_."[ChangedAttributeNames]"
$attrnames = $_."[AttributeNames]"
$objectmodificationtype = $_."[ObjectModificationType]"
$objectguid = $_.objectguidstring
# used to return status to sync engine; we assume that no error will occur
set-actioninfo 'general'
$errorstatus = "success"
$errordetail = ""
$error.clear()
try
{
enable-csuser -registrarpool fepool.domain.local -id "domain\"+$accountname -sipaddress "sip:"+$mail
}
catch
{
$errorstatus = ( "{0}-error" -f $actioninfo )
log -message "ERROR: $errorstatus"
$errordetail = $error[0]
}
# return status about export operation
$status = @{}
$status."[Identifier]" = $identifier
$status."[ErrorName]" = $errorstatus
$status."[ErrorDetail]" = $errordetail
$status
log -message "-- end export entry --"
}
end
{
set-actioninfo "new-pssession"
$null = remove-pssession -session $session
log -message "end export"
}Diego Shimohama