Private/SyncFunctions.ps1


<#
.NOTES
    Company: BitTitan, Inc.
    Title: SyncFunctions.ps1
    Author: SUPPORT@BITTITAN.COM
    Requirements:
     
    Version: 1.1
    Date: DECEMBER 22, 2016
 
    Disclaimer: This script is provided ‘AS IS’. No warrantee is provided either expresses or implied.
 
    Copyright: Copyright© 2016 BitTitan. All rights reserved.
     
.SYNOPSIS
  Uses MigrationWiz to sync AD objects to O365.
 
.DESCRIPTION
  Helper function for the Sync-ADtoO365 tool.
 
#>



function SyncAll([MigrationProxy.WebApi.Ticket]$ticket, $simulate, $delete)
{
    Try 
    {
        $sync = @()

        $syncUsers = SyncUsers -ticket $ticket -simulate $simulate -delete $delete
        $syncContacts = SyncContacts -ticket $ticket -simulate $simulate -delete $delete
        $syncGroups = SyncGroups -ticket $ticket -simulate $simulate -delete $delete

        $sync = $syncUsers,$syncContacts,$syncGroups
        return $sync
    }
    Catch 
    {
        throw
    }

}


function SyncUsers([MigrationProxy.WebApi.Ticket]$ticket, $simulate, $delete)
{
    # build hash-table of params to splat
    $splat = 
    @{
        'Credentials'               = $migrationwizcredentials;
        'Office365Credentials'      = $o365credentials;
        'EnableDeletes'             = $delete;
        'SimulationOnly'            = $simulate;
        'ServerName'                = $global:adSeverName;
        'RootSearchContainer'       = $global:userRootSearchContainer;
        'SearchFilter'              = $global:userSearchFilter;
        'ExclusionFilter'           = $global:userExclusionFilter;
        'DefaultPassword'           = $global:userDefaultPassword;
        'Environment'               = $script:environment;
        'ErrorAction'               = 'Stop'
    }    

    Try 
    {
        $sync = New-ActiveDirectoryToOffice365UserDirectorySync @splat

        return $sync
    }
    Catch 
    {
        throw
    }
} # end SyncUsers function


function SyncContacts([MigrationProxy.WebApi.Ticket]$ticket, $simulate, $delete)
{

    # build hash-table of params to splat
    $splat = 
    @{
        'Credentials'               = $migrationwizcredentials;
        'Office365Credentials'      = $o365credentials;
        'EnableDeletes'             = $delete;
        'SimulationOnly'            = $simulate;
        'ServerName'                = $global:adSeverName;
        'RootSearchContainer'       = $global:userRootSearchContainer;
        'SearchFilter'              = $global:userSearchFilter;
        'ExclusionFilter'           = $global:userExclusionFilter;
        'Environment'               = $script:environment;
        'ErrorAction'               = 'Stop'
    }

    Try 
    {
        $sync = New-ActiveDirectoryToOffice365ContactDirectorySync @splat
                                                        
        return $sync
    }
    Catch 
    {
        throw
    }
} # end SyncContacts function


function SyncGroups([MigrationProxy.WebApi.Ticket]$ticket, $simulate, $delete)
{
    
    # build hash-table of params to splat
    $splat = 
    @{
        'Credentials'               = $migrationwizcredentials;
        'Office365Credentials'      = $o365credentials;
        'EnableDeletes'             = $delete;
        'SimulationOnly'            = $simulate;
        'ServerName'                = $global:adSeverName;
        'RootSearchContainer'       = $global:userRootSearchContainer;
        'SearchFilter'              = $global:userSearchFilter;
        'ExclusionFilter'           = $global:userExclusionFilter;
        'Environment'               = $script:environment;
        'ErrorAction'               = 'Stop'
    }
    Try 
    {
        $sync = New-ActiveDirectoryToOffice365GroupDirectorySync @splat
                                                        
        return $sync
    }
    Catch 
    {
        throw
    }
} # end SyncGroups function