Help: Powershell error using sql agent job

  • Hi I am executing 

    SL "C:\Policy\Powershell\"
    .\EPM_EnterpriseEvaluation_412.ps1 -ConfigurationGroup "prod" -PolicyCategoryFilter "Microsoft Best Practices: Performance" –EvalMode “Check”

    Can anyone help me what's wrong with the syntax???

    I have setup policy base management(powershell script and policies) I followed and go from  https://epmframework.codeplex.com/releases/view/619917

  • Looks like the error is somewhere in the Powershell script EPM_EnterpriseEvaluation_412.ps1

    Sue

  • Sue_H - Tuesday, May 9, 2017 8:05 AM

    Looks like the error is somewhere in the Powershell script EPM_EnterpriseEvaluation_412.ps1

    Sue

    It seems weird if error is on the powershell since when it is executed directly on the powershell it is working fine, the issue is it when it runs thru SQL Job

  • yhandz_21 - Tuesday, May 9, 2017 7:14 PM

    It seems weird if error is on the powershell since when it is executed directly on the powershell it is working fine, the issue is it when it runs thru SQL Job

    The job step type should be Powershell shouldn't it? Were you able to parse the command?

    Sue

  • Sue_H - Tuesday, May 9, 2017 8:25 PM

    yhandz_21 - Tuesday, May 9, 2017 7:14 PM

    It seems weird if error is on the powershell since when it is executed directly on the powershell it is working fine, the issue is it when it runs thru SQL Job

    The job step type should be Powershell shouldn't it? Were you able to parse the command?

    Sue

    I think when i will parse it, obviously it will throw an error. Anyways when I change SL to POWERSHELL it also shows error: Note: Not sure maybe the powershell was using SL based on how it was configured

  • yhandz_21 - Tuesday, May 9, 2017 10:12 PM

    I think when i will parse it, obviously it will throw an error. Anyways when I change SL to POWERSHELL it also shows error: Note: Not sure maybe the powershell was using SL based on how it was configured

    The command that is shown in that window won't work - not sure exactly what you are doing in that one as you wouldn't change a set-location to Powershell. 
    If you are going to run a powershell step in a job, you should be testing the script with SQLPS as that is what the job will use. You should also verify the versions as SQLPS is typically a lower version that the Powershell version for the OS.
    If you need it to run under the version of Powershell for the OS, you need to use a CmdExec job step, call the powershell executable and pass in the script. 
    If there is a dependency on specific snap ins, you should load those as well and check the execution policy if needed.
    Executing commands and scripts are typically different between SQLPS and Powershell. With the defaults, you are in different data store locations when either startup. To view the locations available in powershell, you would use get-psdrive. Being in SQLSERVER:\ is different than being in C:\
    It might be a better idea to work on understanding some of the basics with powershell before trying to run others scripts. You will have a hard time supporting those if you haven't gotten some of the basics down.

    Sue

Viewing 6 posts - 1 through 5 (of 5 total)

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