I went through my script line by line, commented out functions, and re-ran through Task Scheduler with 'Run whether user is logged on or not', until it no longer worked. It finally "failed" when I un-commented the 'exportToPDF' function. Although, it doesn't really fail, Task Scheduler will still show the Last Run Result as successful, it just doesn't seem to actually export anything.
I tried exportToJPEG and exportToPNG, both with the same result as exportToPDF.
Below is a copy of a log my script outputs when I leave the 'exportToPDF' function commented out. Even though it may say successfully exported a PDF, it's simply indicating where the PDF should be written to. You can see the script has no problem accessing the ArcGIS Pro document, updating layer definition queries, turning layers on or off, setting the map frame extent to that of a layer, adjusting the map frame scale, updating layout text elements, etc... it's the 'exportTo...' function that does not work.
Permissions are not an issue. My log is being written to a different server successfully, and the output PDFs are being written to a different server successfully if I change the Task Scheduler property to 'Run only when user is logged on'.
So...even though previous comments indicated this would be fixed at ArcGIS Pro 2.0, it doesn't appear that it has been. Exporting layouts through Task Scheduler with 'Run whether user is logged on or not' seems to be a bug, and not possible, at least based on our system environment, shown below.
System Environment
OS: Windows Server 2012 R2
ArcGIS Pro Version: 2.0
ArcGIS Pro License Type: Single Use Advanced
Task Scheduler Action shown below. I see in the Pro docs it's recommended to use the propy.bat file, so I am, with an argument set to the file path of my script.
![](https://community.esri.com/legacyfs/online/359565_pastedImage_6.png)
Example log file
User: MBoyle
Time: 2017-06-30 10:14:46 AM
Script: E:\GIS-Data\Scripts\DailyReappraisalMaps.py
--------------------------------------------------
2017-06-30 10:14:46 AM: Attempting to truncate ..\Matt\Production\Assessor\Reappraisal\Maps\DailyReappraisal\DailyReappraisal.gdb\asrRprslMapAreaY...
2017-06-30 10:14:48 AM: Successfully truncated ..\Matt\Production\Assessor\Reappraisal\Maps\DailyReappraisal\DailyReappraisal.gdb\asrRprslMapAreaY... (Elapsed time: 1.77 seconds)
2017-06-30 10:14:49 AM: Attempting to load gdb.DBO.svw_asrRprslMapAreaY into ..\Matt\Production\Assessor\Reappraisal\Maps\DailyReappraisal\DailyReappraisal.gdb\asrRprslMapAreaY...
2017-06-30 10:14:54 AM: Successfully loaded 4 rows from gdb.DBO.svw_asrRprslMapAreaY into ..\Matt\Production\Assessor\Reappraisal\Maps\DailyReappraisal\DailyReappraisal.gdb\asrRprslMapAreaY... (Elapsed time: 3.96 seconds)
--------------------------------------------------
2017-06-30 10:14:54 AM: ..Some-Folder\Reappraisal\In-House\Reports\Maps\2017-06-29 already exists; skipping attempt to create...
--------------------------------------------------
2017-06-30 10:14:58 AM: ArcGIS Pro Project: ..\Matt\Production\Assessor\Reappraisal\Maps\DailyReappraisal\DailyReappraisal.aprx
--------------------------------------------------
2017-06-30 10:14:58 AM: Maps:
2017-06-30 10:14:58 AM: Reappraisal
--------------------------------------------------
2017-06-30 10:14:58 AM: Layouts:
2017-06-30 10:14:58 AM: Landscape
2017-06-30 10:14:58 AM: Portrait
--------------------------------------------------
2017-06-30 10:14:58 AM: Orientations:
2017-06-30 10:14:58 AM: L
2017-06-30 10:14:58 AM: P
--------------------------------------------------
2017-06-30 10:14:59 AM: Landscape Features:
2017-06-30 10:14:59 AM: MapArea=Marion 1040
2017-06-30 10:14:59 AM: OID=1
2017-06-30 10:14:59 AM: *~*~*~*~*~*~*~*~*
2017-06-30 10:14:59 AM: MapArea=Marion 1018
2017-06-30 10:14:59 AM: OID=2
--------------------------------------------------
2017-06-30 10:14:59 AM: Portrait Features:
2017-06-30 10:14:59 AM: MapArea=Marion 1024
2017-06-30 10:14:59 AM: OID=3
2017-06-30 10:14:59 AM: *~*~*~*~*~*~*~*~*
2017-06-30 10:14:59 AM: MapArea=Marion 1019
2017-06-30 10:14:59 AM: OID=4
--------------------------------------------------
2017-06-30 10:14:59 AM: Attempting to update 'Parcels Visited Yesterday' layer name within 'Reappraisal' map to 'Parcels Visited 06/29/2017'...
2017-06-30 10:14:59 AM: Successfully updated 'Parcels Visited Yesterday' layer name within 'Reappraisal' map to 'Parcels Visited 06/29/2017'... (Elapsed time: 0.00 seconds)
--------------------------------------------------
2017-06-30 10:15:08 AM: There are 2 landscape pages to export...
--------------------------------------------------
2017-06-30 10:15:08 AM: Attempting to turn on 'Assessor Map Area Index (L)' layer within 'Reappraisal' map...
2017-06-30 10:15:08 AM: Successfully turned on 'Assessor Map Area Index (L)' layer within 'Reappraisal' map... (Elapsed time: 0.00 seconds)
--------------------------------------------------
2017-06-30 10:15:08 AM: Attempting to turn off 'Assessor Map Area Index (P)' layer within 'Reappraisal' map...
2017-06-30 10:15:08 AM: Successfully turned off 'Assessor Map Area Index (P)' layer within 'Reappraisal' map... (Elapsed time: 0.00 seconds)
--------------------------------------------------
2017-06-30 10:15:08 AM: Attempting to update definition query of 'Assessor Map Area Index (L)' layer to 'OBJECTID=1'...
2017-06-30 10:15:08 AM: Successfully updated definition query of 'Assessor Map Area Index (L)' layer to 'OBJECTID=1'... (Elapsed time: 0.04 seconds)
2017-06-30 10:15:08 AM: Attempting to set 'Data View Map Frame' map frame within 'Landscape' layout to the extent of the 'Assessor Map Area Index (L)' layer...
2017-06-30 10:15:08 AM: Successfully set 'Data View Map Frame' map frame within 'Landscape' layout to the extent of the 'Assessor Map Area Index (L)' layer... (Elapsed time: 0.03 seconds)
2017-06-30 10:15:08 AM: Attempting to apply a 5.0% padding to 'Landscape' layout scale; setting layout scale to 1:8,965...
2017-06-30 10:15:08 AM: Successfully applied a 5.0% padding to 'Landscape' layout scale; setting layout scale to 1:8,965... (Elapsed time: 0.01 seconds)
2017-06-30 10:15:08 AM: Attempting to update 'Landscape' layout 'MapArea' text element to 'Marion 1040'...
2017-06-30 10:15:08 AM: Successfully updated 'Landscape' layout 'MapArea' text element to 'Marion 1040'... (Elapsed time: 0.00 seconds)
2017-06-30 10:15:08 AM: Attempting to export 'Landscape' layout to: ..Some-Folder\Reappraisal\In-House\Reports\Maps\2017-06-29\Marion 1040.pdf...
2017-06-30 10:15:08 AM: Successfully exported 'Landscape' layout to: ..Some-Folder\Reappraisal\In-House\Reports\Maps\2017-06-29\Marion 1040.pdf... (Elapsed time: 0.00 seconds)
--------------------------------------------------
2017-06-30 10:15:08 AM: Attempting to update definition query of 'Assessor Map Area Index (L)' layer to 'OBJECTID=2'...
2017-06-30 10:15:08 AM: Successfully updated definition query of 'Assessor Map Area Index (L)' layer to 'OBJECTID=2'... (Elapsed time: 0.04 seconds)
2017-06-30 10:15:08 AM: Attempting to set 'Data View Map Frame' map frame within 'Landscape' layout to the extent of the 'Assessor Map Area Index (L)' layer...
2017-06-30 10:15:08 AM: Successfully set 'Data View Map Frame' map frame within 'Landscape' layout to the extent of the 'Assessor Map Area Index (L)' layer... (Elapsed time: 0.03 seconds)
2017-06-30 10:15:08 AM: Attempting to apply a 5.0% padding to 'Landscape' layout scale; setting layout scale to 1:5,612...
2017-06-30 10:15:08 AM: Successfully applied a 5.0% padding to 'Landscape' layout scale; setting layout scale to 1:5,612... (Elapsed time: 0.01 seconds)
2017-06-30 10:15:08 AM: Attempting to update 'Landscape' layout 'MapArea' text element to 'Marion 1018'...
2017-06-30 10:15:08 AM: Successfully updated 'Landscape' layout 'MapArea' text element to 'Marion 1018'... (Elapsed time: 0.00 seconds)
2017-06-30 10:15:08 AM: Attempting to export 'Landscape' layout to: ..Some-Folder\Reappraisal\In-House\Reports\Maps\2017-06-29\Marion 1018.pdf...
2017-06-30 10:15:08 AM: Successfully exported 'Landscape' layout to: ..Some-Folder\Reappraisal\In-House\Reports\Maps\2017-06-29\Marion 1018.pdf... (Elapsed time: 0.00 seconds)
--------------------------------------------------
2017-06-30 10:15:08 AM: There are 2 portrait pages to export...
--------------------------------------------------
2017-06-30 10:15:08 AM: Attempting to turn on 'Assessor Map Area Index (P)' layer within 'Reappraisal' map...
2017-06-30 10:15:08 AM: Successfully turned on 'Assessor Map Area Index (P)' layer within 'Reappraisal' map... (Elapsed time: 0.00 seconds)
--------------------------------------------------
2017-06-30 10:15:08 AM: Attempting to turn off 'Assessor Map Area Index (L)' layer within 'Reappraisal' map...
2017-06-30 10:15:08 AM: Successfully turned off 'Assessor Map Area Index (L)' layer within 'Reappraisal' map... (Elapsed time: 0.00 seconds)
--------------------------------------------------
2017-06-30 10:15:08 AM: Attempting to update definition query of 'Assessor Map Area Index (P)' layer to 'OBJECTID=3'...
2017-06-30 10:15:08 AM: Successfully updated definition query of 'Assessor Map Area Index (P)' layer to 'OBJECTID=3'... (Elapsed time: 0.04 seconds)
2017-06-30 10:15:08 AM: Attempting to set 'Data View Map Frame' map frame within 'Portrait' layout to the extent of the 'Assessor Map Area Index (P)' layer...
2017-06-30 10:15:08 AM: Successfully set 'Data View Map Frame' map frame within 'Portrait' layout to the extent of the 'Assessor Map Area Index (P)' layer... (Elapsed time: 0.03 seconds)
2017-06-30 10:15:08 AM: Attempting to apply a 5.0% padding to 'Portrait' layout scale; setting layout scale to 1:4,046...
2017-06-30 10:15:08 AM: Successfully applied a 5.0% padding to 'Portrait' layout scale; setting layout scale to 1:4,046... (Elapsed time: 0.01 seconds)
2017-06-30 10:15:08 AM: Attempting to update 'Portrait' layout 'MapArea' text element to 'Marion 1024'...
2017-06-30 10:15:08 AM: Successfully updated 'Portrait' layout 'MapArea' text element to 'Marion 1024'... (Elapsed time: 0.00 seconds)
2017-06-30 10:15:08 AM: Attempting to export 'Portrait' layout to: ..Some-Folder\Reappraisal\In-House\Reports\Maps\2017-06-29\Marion 1024.pdf...
2017-06-30 10:15:08 AM: Successfully exported 'Portrait' layout to: ..Some-Folder\Reappraisal\In-House\Reports\Maps\2017-06-29\Marion 1024.pdf... (Elapsed time: 0.00 seconds)
--------------------------------------------------
2017-06-30 10:15:08 AM: Attempting to update definition query of 'Assessor Map Area Index (P)' layer to 'OBJECTID=4'...
2017-06-30 10:15:08 AM: Successfully updated definition query of 'Assessor Map Area Index (P)' layer to 'OBJECTID=4'... (Elapsed time: 0.04 seconds)
2017-06-30 10:15:08 AM: Attempting to set 'Data View Map Frame' map frame within 'Portrait' layout to the extent of the 'Assessor Map Area Index (P)' layer...
2017-06-30 10:15:08 AM: Successfully set 'Data View Map Frame' map frame within 'Portrait' layout to the extent of the 'Assessor Map Area Index (P)' layer... (Elapsed time: 0.03 seconds)
2017-06-30 10:15:08 AM: Attempting to apply a 5.0% padding to 'Portrait' layout scale; setting layout scale to 1:4,815...
2017-06-30 10:15:08 AM: Successfully applied a 5.0% padding to 'Portrait' layout scale; setting layout scale to 1:4,815... (Elapsed time: 0.01 seconds)
2017-06-30 10:15:08 AM: Attempting to update 'Portrait' layout 'MapArea' text element to 'Marion 1019'...
2017-06-30 10:15:08 AM: Successfully updated 'Portrait' layout 'MapArea' text element to 'Marion 1019'... (Elapsed time: 0.00 seconds)
2017-06-30 10:15:08 AM: Attempting to export 'Portrait' layout to: ..Some-Folder\Reappraisal\In-House\Reports\Maps\2017-06-29\Marion 1019.pdf...
2017-06-30 10:15:08 AM: Successfully exported 'Portrait' layout to: ..Some-Folder\Reappraisal\In-House\Reports\Maps\2017-06-29\Marion 1019.pdf... (Elapsed time: 0.00 seconds)
--------------------------------------------------
2017-06-30 10:15:10 AM: End time of script (Elapsed time: 24.06 seconds)
--------------------------------------------------