Attempting to run PS / DBA tools script as a SQL Agent job

  • If I run my PS script with PS as an ADMIN interactively it runs fine.  If I attempt to run it as a SQL Agent job it has issues.  I think the problem is it needs to run as an ADMIN but I cannot figure out how to do that.  Has anyone had issues running a PS Script as a SQL Agent job?  The ID running this is an Admin on the server and within SQL Server as well.

     

    New-Item : Access to the path 'C:\Users\SVC_TP~1\AppData' is denied.

    At line:28 char:13

    + $null = New-Item -Path $temp -ItemType Directory -Force

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo : PermissionDenied: (C:\Users\SVC_TP~1\AppData\Local\Temp:String) [Ne

    w-Item], UnauthorizedAccessException

    + FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft.PowerShell.Command

    s.NewItemCommand

  • The sqljob proxy account ( or sqlagent service account is no proxy account is used ) needs to be granted the needed authority to run the script.

    Don't use "C:\Users\..." as those always are more secured than regular folders e.g. C:\PoSh\..."

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • That account is an Admin on the server.  Also, I am not sure where the C:\Users comes into play because I am not specifying that at all.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply