Always On

New-sqmAutoLoginSyncJob

Creates a SQL Agent job that runs Sync-Job.ps1 daily at 2:00 AM to synchronize SQL logins across Always On replicas. Sets up the output directory with permissions for the SQL Server and SQL Server Agent service accounts.

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

Execution Flow

START Create C:\System\WinSrvLog\MSSQL + icacls for SQL/SQLAgent accounts Job exists & not -Force? Yes throw error No If -Force & existing: Remove-DbaAgentJob New-DbaAgentJob (sqmAutoLoginSync) New-DbaAgentJobStep RunSync (CmdExec: powershell.exe -File Sync-Job.ps1) sp_add_schedule + sp_attach_schedule (daily 02:00) Return PSCustomObject (Status=Success) DONE
The schedule runs the sync script daily at 02:00 via the SQL Agent CmdExec subsystem, executing the standalone Sync-Job.ps1 packaged with the module — not a PowerShell subsystem step. Use -Force to recreate an existing job.

Parameters

ParameterTypeRequiredDescription
-SqlInstanceStringOptionalTarget SQL instance. Default: $env:COMPUTERNAME.
-JobNameStringOptionalName of the Agent job. Default: sqmAutoLoginSync.
-ForceSwitchOptionalOverwrites an existing job with the same name.
-WhatIfSwitchOptionalPreview actions without creating the job.
-ConfirmSwitchOptionalPrompt before creating the job.

Return Value

Returns a PSCustomObject with: SqlInstance, JobName, Status (Success), Message, Timestamp.

Examples

Example 1 — Create job with default schedule

New-sqmAutoLoginSyncJob -SqlInstance "SQL01"

Example 2 — Replace existing job

New-sqmAutoLoginSyncJob -SqlInstance "SQL01" -Force