0 votes

I have a script that i am trying to run against all users in an OU, but the script will only run against 1 user then not run again for any other users in the OU. Any thoughts on why this would happen?

by (100 points)
0

Hello,

Could you send us or post here a screenshot of the Business Rule (Custom Command or Scheduled Task) that executes the script? Make sure the screenshot includes the Activity Scope. We need something like the following:

Also, provide the script you are using.

0

Sorry for the delay in the reply. Here is the rule and the associated errors. I am trying to check for users that were create on prem and have finally synced to O365 then migrate the mailbox to office 365 for the user.

Capture of the Rule


Script Migrate Mailbox to Office 365

    Import-Module MsOnline
    Try
    {
        Connect-MsolService -Credential $Context.GetOffice365Credential()
    }
    Catch
    {

        $Context.LogMessage("Unable to connect to Office 365", "Error")
        return
    } 
    # Find a corresponding account in Office 365
    #$userPrincipalName = %userPrincipalName%    
    $Context.LogMessage("Looking for Account - %userPrincipalName%", "Information")
    $found = $false
    While($found -eq $False)
    {
        Try
            {
            $user = Get-MsolUser -UserPrincipalName %userPrincipalName% -ErrorAction SilentlyContinue
            }
        Catch
            {

            }
            If($user -ne $null)
            {            
                $Context.LogMessage("User account for %userPrincipalName% found in Office 365, attempting to move mailbox to Office 365", "Information")
                $office365DeliveryDomain = "<Delivery domain" # TODO: modify me

                # Connect to Exchange Online
                $session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://outlook.office365.com/powershell-liveid/" `
                -Credential $Context.GetOffice365Credential() -Authentication Basic -AllowRedirection
                Import-PSSession $session -AllowClobber -DisableNameChecking 

                # Credentials of the local Exchange domain administrator
                $localAdminName = <Serviceaccount>

                $localAdminPassword = ConvertTo-SecureString -AsPlainText -Force -String <Password> 
                $localAdminCredentials = New-Object -TypeName System.Management.Automation.PSCredential($localAdminName, $localAdminPassword)

                try
                {
                    $result = New-MoveRequest -Identity %username% -BatchName %username%  -Remote -RemoteHostName "Remote host domain" -TargetDeliveryDomain $office365DeliveryDomain -RemoteCredential $localAdminCredentials  -ErrorAction Stop  

                }
                catch
                {
                    $Context.LogMessage("Unable to create Move Request for %username%", "Error")
                    $Context.LogMessage($_.Exception.Message, "Error")
                }

                    if ($result -ne $NULL)
                    {
                        $Context.LogMessage("Mailbox move request created successfully. Check Exchange logs for details." , "Information")
                    }
                    Remove-PSSession $Session
                    return # exit script
                    $found = $true    
            }
            Else
            {

             $Context.LogMessage("User has not synced with Office 365 yet, sleeping 10 minutes and checking again." , "Information")
            Start-Sleep -Seconds 600
            }

    }

User in AD has the extensionattribute3 set

Script reports nothing in the activity log

Error in event log from the adaxes service looking for the user online

O365 search for the same user finds the user without issue. (sorry couldn't add another screen shot.

0

Hello,

I have a script that i am trying to run against all users in an OU, but the script will only run against 1 user then not run again for any other users in the OU.

According to the screenshot of the Scheduled Task, it should affect only users located in the Users OU, but not in its child OUs. Could you make sure there are other user accounts that match the conditions specified in the task?

Script Migrate Mailbox to Office 365

Could you specify, what exactly you need the script to do? Should it just move mailboxes to office 365?
Also, the timeout for script execution in Adaxes is 10 minutes. Your script will not work as it contains sleep for 600 seconds.

Script reports nothing in the activity log

It means that the error message you see in Adaxes Event log is not related to the script. Probably, it occurred for some other action.

0

According to the screenshot of the Scheduled Task, it should affect only users located in the Users OU, but not in its child OUs. Could you make sure there are other user accounts that match the conditions specified in the task?

I have tried with multiple accounts in this OU but even at this point with one account, it is not being processed or the script is not completing successfully against the account.

Could you specify, what exactly you need the script to do? Should it just move mailboxes to office 365?
Also, the timeout for script execution in Adaxes is 10 minutes. Your script will not work as it contains sleep for 600 seconds.

I am looking for the script to poll and check for the extension attribute on the user the verify the user has been synced to Office 365. If so attempt to move the mailbox. If not wait till the next polling time and then run again. the sleep code i forgot to take out, you are correct it doesn't work (was orginially trying to testing and move based on user creation but found out about the 10 minute limit)

It means that the error message you see in Adaxes Event log is not related to the script. Probably, it occurred for some other action.

The error in the event log if specific to the running of the script (Migrate Mailbox to Office 365 is the name of the scheduled task) the kevin.test5 user is the account that is in the OU i am attempting to run the script against, but is only looking at that one server and not finding the account. I can run the script and that error is created in the log after each run

1 Answer

0 votes
by (289k points)
selected by
Best answer

Hello,

We recommend the following approach:

The first set of actions and conditions in the Scheduled Task will initiate a move mailbox request and set a Boolean property to True for the user to mark that the request was created for them. We recommend using one of Adaxes custom Boolean attributes (e.g. CustomAttributeBoolean1).

The second set of actions and conditions in the Scheduled Task will check the Boolean property value. If the property is set to True, a PowerShell script will check the move mailbox request status and clear the Boolean property if the request is completed. If the request is not completed yet (e.g. queued or in progress) or failed the script will add a corresponding message to the Execution log. If this solution meets your needs, we will provide you with detailed instructions.

Regarding the error message you see in the event log. It looks like it is produced by another script in the Scheduled Task (Test or Check Office 365 for user mailbox). If you provide us with the scripts, we will check them for possible causes of the error.

Related questions

0 votes
1 answer

Hello, We would like to implement a form / extend one where a user (eventually created before) is made member of a security group defining his/her role, and ... guarantee the membership to a single role? Apologize if the question seems convoluted. Thanks!

asked Jun 6, 2023 by IT Division (20 points)
0 votes
1 answer

seting up a scheduled task to move users to thier correct OU. For some we can do this based on employee type and direct to a specific OU. For most of our users we will have to script this to move to the manager's OU.

asked Apr 12, 2023 by mightycabal (1.0k points)
0 votes
1 answer

Hi there, I've created a Delete User feature in the Web Interface Configurator. I am trying to restrict object selection via a User Criteria. Need to exclude Service ... won't appear when selecting target user for the 'Delete User' feature. Thanks, David

asked Sep 19 by dshortall (80 points)
0 votes
1 answer

I'm trying to schedule a report to look in a few specific OUs. Currently "Look in" location only allows for single instance or multiple drop downs. How do I schedule multiple OU locations without creating multiple reports?

asked Jul 2, 2020 by Al (20 points)
0 votes
1 answer

In a business rule, I'd like to pass Adaxes variables into a powershell script that I'll run. For example, pass %username% into the script so it can be used inside the script.

asked Sep 5 by P-Sysadmin (20 points)
3,547 questions
3,238 answers
8,232 comments
547,809 users