Powershell脚本正在执行但无法正常工作

时间:2015-05-15 10:55:36

标签: powershell sql-agent-job

我有一个Powershell脚本,可以在Windows power shell IDE中正常运行。但是,当我从SQL代理程序作业运行它时,它运行时没有错误,但它没有执行任何操作。以下是我在工作历史中收到的消息

public class ListaActivity extends ActionBarActivity{
    StartActivity startActiv;
    private List<String> mLista = new ArrayList<>();
    private ListView mListView;
    private MiastaListAdapter mAdapter;
    public Elements jobName, jobName2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lista_miast);  
        mListView = (ListView) findViewById(R.id.lista_miast);  
        new NewThread().execute();
        mAdapter = new MiastaListAdapter(this, mLista);
        mListView.setAdapter(mAdapter);
    }

    public class NewThread extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... arg) {
            String doURLwork = startActiv.nazwaStanowiska;
            String doURLplace = startActiv.nazwaMiejscowosci;

            Document doc;
            try {
                doc = (Document) Jsoup.connect("http://www.infopraca.pl/praca?q=" + doURLwork + "&lc=" + doURLplace)
                        .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0").get();

                jobName = doc.select("h2.p-job-title a[href]"); //infopraca

                    for (Element jobNames : jobName) {
                        mLista.add(jobNames.text() + "\n");
                    }

            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(String result) {
            mAdapter.notifyDataSetChanged();
        }
    }
}

虽然,我已从“DOMAIN \ SERVICEACCOUNT”的服务帐户运行它,但它显示“SERVERNAME ** SYSTEM **

如果需要更多详细信息,请与我们联系。

编辑 - 作业脚本

     Executed as user: SERVER\SYSTEM. The string starting:  At line:1 
    char:1  +  <<<< "D:\FOLDER\POWERSCRIPT.ps1?  is missing the terminator: ". 
     At line:1 char:23  + "D:\FOLDER\POWERSCRIPT.ps1? <<<<      
     + CategoryInfo          : ParserError: (D:\FOLDER\POWERSCRIPT.ps1?:String) [],       ParentContainsErrorRecordException     
 + FullyQualifiedErrorId : 
TerminatorExpectedAtEndOfString.  Process Exit Code 0.  The step succeeded.

1 个答案:

答案 0 :(得分:1)

@command=N'powershell “D:\FOLDER\POWERSCRIPT.ps1″',

这里的引号看起来并不合适。您应该删除它们并将它们重新键入为双引号,如下所示:

@command=N'powershell "D:\FOLDER\POWERSCRIPT.ps1"',

你能看出区别吗?复制和粘贴值时有时会发生这种情况。