Execution Flow
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. Jobs created since v1.9.168.0 use the Union sync automatically after the module update (it is the new default of Sync-sqmLoginsToAlwaysOn); recreate them with -Force once to also get the failover alert.Renamed in v1.9.209.0 from
New-sqmAutoLoginSyncJob; the old name still works as an alias. The parameter file is named <Job>_<Instance>_<Step>.clixml, so several instances on one server do not overwrite each other. Logs and reports default to <SQL Server installation drive>:\sqm\Log and \sqm\Output, where the Agent service account can write. Only one Agent alert on message 1480 exists per instance: with two AGs on one instance the second job is not started by the alert.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| -SqlInstance | String | Optional | Target SQL instance. Default: $env:COMPUTERNAME. Can be a remote server: the wrapper and parameter file are then written to that server via the C$ admin share (the module must be installed there). |
| -AvailabilityGroupName | String | Optional | AG to sync. Default: the first AG on the instance. |
| -JobName | String | Optional | Name of the Agent job. Default: sqmAutoLoginSync. A second AG on the same instance needs its own name. |
| -AuditAdOrphans | Switch | Optional | After each run, report Windows logins without an AD account (event 9003). Detection only, nothing is deleted. |
| -BackupRetentionDays | Int | Optional | Retention for login backups and audit reports in days. Sync default: 7, 0 keeps all. |
| -NoFailoverAlert | Switch | Optional | Do not create the Agent alert on message 1480 that starts the job after a failover. |
| -Force | Switch | Optional | Overwrites an existing job with the same name. |
| -WhatIf | Switch | Optional | Preview actions without creating the job. |
| -Confirm | Switch | Optional | Prompt before creating the job. |
Return Value
Returns the result of Install-sqmStandardJob: Name, SqlInstance, JobName, FunctionName, Parameters, ScheduleName, PrimaryOnly, AlertName, AlertStatus, Started, Status, Message, Timestamp.
Examples
Example 1, Create job with default schedule
New-sqmAlwaysOnLoginSyncJob -SqlInstance "SQL01"Example 2, Replace an old job, with AD orphan report
New-sqmAlwaysOnLoginSyncJob -SqlInstance "SQL01" -AvailabilityGroupName "ProdAG" -AuditAdOrphans -Force