· Uwe Janke
Commands / New-sqmAutoLoginSyncJob
Always On

New-sqmAutoLoginSyncJob

Creates the SQL Agent job for the automatic AlwaysOn login sync. Since v1.9.168.0 this is a shortcut for Install-sqmStandardJob -Name AgLoginSync: Sync-sqmLoginsToAlwaysOn -Force:$false daily at 2:00 AM, only missing logins are added. Install it on every replica, only the current primary does the work.

Module: sqmSQLTool
Requires: dbatools
ShouldProcess: Yes
Output: PSCustomObject

Execution Flow

START Collect -AvailabilityGroupName, -AuditAdOrphans, -BackupRetentionDays Install-sqmStandardJob -Name AgLoginSync (job sqmAutoLoginSync) CmdExec step, PrimaryOnly, Sync-sqmLoginsToAlwaysOn -Force:$false, daily 02:00 DONE
On a secondary the job step ends with success without doing anything, so after a failover the new primary takes over. Jobs created by older versions (step calls jobs\Sync-Job.ps1) keep running; recreate them with -Force to switch over.

Parameters

ParameterTypeRequiredDescription
-SqlInstanceStringOptionalTarget SQL instance. Default: $env:COMPUTERNAME.
-AvailabilityGroupNameStringOptionalAG to sync. Default: the first AG on the instance.
-JobNameStringOptionalName of the Agent job. Default: sqmAutoLoginSync.
-AuditAdOrphansSwitchOptionalAfter each run, report Windows logins without an AD account (event 9003). Detection only, nothing is deleted.
-BackupRetentionDaysIntOptionalRetention for login backups and audit reports in days. Sync default: 7, 0 keeps all.
-ForceSwitchOptionalOverwrites an existing job with the same name.
-WhatIfSwitchOptionalPreview actions without creating the job.
-ConfirmSwitchOptionalPrompt before creating the job.

Return Value

Returns the result of Install-sqmStandardJob: Name, SqlInstance, JobName, FunctionName, Parameters, ScheduleName, PrimaryOnly, Started, Status, Message, Timestamp.

Examples

Example 1, Create job with default schedule

New-sqmAutoLoginSyncJob -SqlInstance "SQL01"

Example 2, Replace an old job, with AD orphan report

New-sqmAutoLoginSyncJob -SqlInstance "SQL01" -AvailabilityGroupName "ProdAG" -AuditAdOrphans -Force