Access denied on Import-Module in a powershell script after upgrade Windows 2019
search cancel

Access denied on Import-Module in a powershell script after upgrade Windows 2019

book

Article ID: 242995

calendar_today

Updated On:

Products

Autosys Workload Automation Workload Automation Agent ESP dSeries Workload Automation - System Agent (dSeries) ESP Workload Automation

Issue/Introduction

After upgrading our Windows servers to Windows 2019 and updated Autosys agent to align with the compatibility matrix.

Since this upgrade, we get an access denied with the command Import-Module ActiveDirectory:

Import-Module : Win32 internal error "Access is denied" 0x5 occurred while reading the console output buffer. Contact
Microsoft Customer Support Services.
At D:\folder123\Autosys\test\Delete-Users.ps1:66 char:1
+ Import-Module ActiveDirectory -verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ReadError: (:) [Import-Module], HostException
    + FullyQualifiedErrorId : ReadConsoleOutput,Microsoft.PowerShell.Commands.ImportModuleCommand

runs : The term 'runs' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\folder123\Autosys\test\Delete-Users-xxxx.ps1:69 char:1
+ runs
+ ~~~~
    + CategoryInfo          : ObjectNotFound: (runs:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

This error occurs only when the command is executed through Autosys. 

We tried several execution mode with the same account on the same server:

  • executed directly with a command line
  • executed by a runas
  • executed in scheduled task

Environment

Release : ANY

Component : Workload Automation Agent

Resolution

Added following agent parameter in the agent's agentparm.txt file;

oscomponent.su.newconsole=true

Restart the agent for the change to take effect..

Additional Information

oscomponent.su.newconsole
(Windows only) Sets whether to force the agent to create a console when running a Windows job.

  • true - Creates a console when running a Windows job.
  • false - Does not create a console when running a Windows job.

Default: false