I am trying to automate my administrative processes with Python for my enterprise geodatebase. I basically took the script at the end found here: Use Python scripting to batch reconcile and post versions—ArcGIS Help | ArcGIS Desktop and trimmed out the parts I do not need. I cannot for the life of me figure out why it bombs when run via a scheduled task.
Using 10.6.1, sde is the admin level, gis user is the owner of the data.
#, time, smtplib
# Set the workspace
arcpy.env.workspace = r'C:\Users\GISAdmin\AppData\Roaming\ESRI\Desktop10.6\ArcCatalog\SDE to GIS2.sde'
# sde is the user that can disconnect users
# gis is the owner of of all the data
# Set a variable for the workspace
adminConn = arcpy.env.workspace
# Block new connections to the database.
print("The database is no longer accepting connections")
print("Credit Card Declined")
# Wait 15 minutes
# Disconnect all users from the database.
print("Disconnecting all users")
# Get a list of versions to pass into the ReconcileVersions tool.
# Only reconcile versions that are children of Default
print("Compiling a list of versions to reconcile")
verList = arcpy.ListVersions(adminConn)
#versionList = [ver.name for ver in verList if ver.parentVersionName == 'sde.DEFAULT']
# Execute the ReconcileVersions tool.
print("Reconciling all versions")
arcpy.ReconcileVersions_management(adminConn, "ALL_VERSIONS", "sde.DEFAULT", u'WEBSERVICES.WebEdits', "LOCK_ACQUIRED", "NO_ABORT", "BY_OBJECT", "FAVOR_TARGET_VERSION", "POST", "KEEP_VERSION", "c:/ArcGISscripts/ReconcileLogs/Temp/reconcilelog.txt")
# Run the compress tool.
# Allow the database to begin accepting connections again
print("Allow users to connect to the database again")
print("Communications Back On Line Captain")
# Update statistics and indexes for the system tables
# Note: to use the "SYSTEM" option the user must be an geodatabase or database administrator.
# Rebuild indexes on the system tables
print("Rebuilding indexes on the system tables")
# Update statistics on the system tables
print("Updating statistics on the system tables")
print("Analyzed Data sets")
print("YAY!!! We Finished For Once.")