Esri / arcgis-powershell-dsc

This repository contains scripts, code and samples for automating the install and configuration of ArcGIS (Enterprise and Desktop) using Microsoft Windows PowerShell DSC (Desired State Configuration).
Apache License 2.0
118 stars 62 forks source link

"Access is denied" when running Invoke-ArcGISConfiguration from batch file (.bat) #402

Open ericandersondhshq opened 2 years ago

ericandersondhshq commented 2 years ago

Community Note

Module Version

Affected Resource(s)

Configuration Files

{
    "AllNodes": [
        {
            "NodeName": "<REDACTED>",
            "Role": [
                "Server"
            ]
        },
        {
            "NodeName": "<REDACTED>",
            "Role": [
                "Server"
            ]
        }
    ],
    "ConfigData": {
        "Version": "10.8.1",
        "ServerContext": "host",
        "ServerRole": "GeneralPurposeServer",
        "Credentials": {
            "ServiceAccount": {
                "Password": "<REDACTED>",
                "UserName": "<REDACTED>",
                "IsDomainAccount": true,
                "IsMSAAccount": false
            }
        },
        "Server": {
            "LicenseFilePath": "\\\\giishare\\prod\\gis\\software\\esri\\1081\\enterprise\\licenses\\ArcGISGISServerAdvanced_ArcGISServer_957633.prvc",
            "Installer": {
                "Path": "\\\\giishare\\prod\\gis\\software\\esri\\1081\\enterprise\\ArcGIS_Server_Windows_1081_175203.exe",
                "InstallDir": "E:\\Programs\\ArcGIS\\Server",
                "InstallDirPython": "E:\\Python27",
                "PatchesDir": "\\\\giishare\\prod\\gis\\software\\esri\\1081\\enterprise\\patches\\server",
                "EnableArcMapRuntime": true,
                "EnableDotnetSupport": false
            },
            "ServerDirectoriesRootLocation": "\\\\giishare\\prod\\arcgis\\hst\\directories",
            "ConfigStoreLocation": "\\\\giishare\\prod\\arcgis\\hst\\config-store",
            "PrimarySiteAdmin": {
                "UserName": "<REDACTED>",
                "Password": "<REDACTED>"
            }
        }
    }
}

Expected Behavior

Run ArcGIS Install as expected.

Actual Behavior

Getting "Access is denied" error.

Steps to Reproduce

We created a batch (.bat) file with following lines of code:

@echo on
cd /D E:\Logs_1081_Install
PowerShell.exe -ExecutionPolicy Bypass -Command "Invoke-ArcGISConfiguration -ConfigurationParametersFile \\giishare\prod\gis\powershell\gii\config\331\1081\prod-host.json -Mode Install -DebugSwitch"

When we run the .bat file from Windows Task Scheduler, within 1 minute of the task running it creates a Log folder for each of the nodes with a VERBOSE file and an ERROR file, and then task stops running pretty quickly.

VERBOSE log:

7/7/2022 10:19:43 PM: Perform operation 'Invoke CimMethod' with following parameters, ''methodName' = SendConfigurationApply,'className' = MSFT_DSCLocalConfigurationManager,'namespaceName' = root/Microsoft/Windows/DesiredStateConfiguration'. 7/7/2022 10:19:43 PM: Operation 'Invoke CimMethod' complete.

ERROR log:

7/7/2022 10:19:43 PM: Access is denied.

If we run the same Powershell command via the Powershell console, it runs fine. We assume the issue is because we have to run the task under SYSTEM (the local machine). When running from Powershell console under our own admin account, no issues. Unfortunately we cannot run the task under our own admin accounts or as a service account.

We've ensured the task is set to run with "Highest privileges".

What directory permissions are required here? We made sure the SYSTEM thats running the task has full read/write permissions to:

cameronkroeker commented 2 years ago

Hi @ericandersondhshq,

Have you tried creating a credential object and using/passing in the -Credential parameter with the Invoke-ArcGISConfiguration command? For example:

Invoke-ArcGISConfiguration -ConfigurationParametersFile C:\config\BaseDeployment.json -Mode InstallLicenseConfigure -Credential Domain\username

This way when the task scheduler kicks off as SYSTEM it will run the Invoke-ArcGISConfiguration command as the admin user that has the correct access to the target node(s). Though I am not entirely sure how this would be done in a batch script, might need to use a powershell script instead.

Hope this helps!

Thanks, Cameron K.

ericandersondhshq commented 2 years ago

Thank you @cameronkroeker ! This helps. Out of curiosity, do you have any sample Powershell scripts of how to run the Invoke-ArcGISConfiguration command remotely from Task Scheduler? I searched through the Wiki and couldn't find anything.

ericandersondhshq commented 2 years ago

Hi @cameronkroeker - I just wanted to follow up on this. Do you have a sample Powershell script file (.ps1) that gives an idea of the proper syntax needed to run the Invoke-ArcGISConfiguration command silently (from Task Scheduler). Thank you in advance!

github-actions[bot] commented 5 days ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.