Search code examples
sql-serversqlcmd

SQLCMD syntax to alter Login Properties and disable "Enforce Password expiration"


I am trying to create a SQLCMD script and run it as a Windows Batch file. Which will disable "Enforce Password expiration" for an existing Login Name in Microsoft SQL Server.

Screenshot

So I am not trying to create new login, but alter existing one.

This is what .sql script looks like for TestUser:

USE [master] GO ALTER LOGIN [TestUser] WITH DEFAULT_DATABASE=[master], DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=ON GO

Thank you all.


Solution

  • Here's a one-liner you can run from cmd:

    echo ALTER LOGIN [TestUser] WITH CHECK_EXPIRATION=OFF | sqlcmd -S localhost -E -d master
    

    Replace localhost with your server and alternately specify SQL login info (-U and -P) instead of trusted login (-E) for a login that has admin privileges to change this.