Powershell 脚本正在执行但不工作
Powershell script is executing but not working
我有一个 Powershell 脚本,它在 Windows power shell IDE 中 运行 很好。但是当我 运行 它来自 SQL 代理工作时它是 运行 没有错误,但它没有做任何操作。以下是我在工作历史记录中收到的消息
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.
尽管如此,我从 "DOMAIN\SERVICEACCOUNT" 的服务帐户中获得了 运行 它,但它向我显示“SERVERNAME**SYSTEM**
如果需要更多详细信息,请告诉我。
编辑作业脚本
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'MYJOB',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'No description available.',
@category_name=N'[Uncategorized (Local)]',
@owner_login_name=N'DOMAIN\SERVICEAACCOUNT', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [RUN MONITOR] Script Date: 5/15/2015 11:01:29 AM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'RUN MONITOR',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'CmdExec',
@command=N'powershell “D:\FOLDER\POWERSCRIPT.ps1″',
@flags=0
@command=N'powershell “D:\FOLDER\POWERSCRIPT.ps1″',
这里的引号看起来不对。您应该删除它们并将它们重新键入为双引号,如下所示:
@command=N'powershell "D:\FOLDER\POWERSCRIPT.ps1"',
你能看出区别吗?复制和粘贴值时有时会发生这种情况。
我有一个 Powershell 脚本,它在 Windows power shell IDE 中 运行 很好。但是当我 运行 它来自 SQL 代理工作时它是 运行 没有错误,但它没有做任何操作。以下是我在工作历史记录中收到的消息
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.
尽管如此,我从 "DOMAIN\SERVICEACCOUNT" 的服务帐户中获得了 运行 它,但它向我显示“SERVERNAME**SYSTEM**
如果需要更多详细信息,请告诉我。
编辑作业脚本
DECLARE @jobId BINARY(16)
EXEC @ReturnCode = msdb.dbo.sp_add_job @job_name=N'MYJOB',
@enabled=1,
@notify_level_eventlog=0,
@notify_level_email=0,
@notify_level_netsend=0,
@notify_level_page=0,
@delete_level=0,
@description=N'No description available.',
@category_name=N'[Uncategorized (Local)]',
@owner_login_name=N'DOMAIN\SERVICEAACCOUNT', @job_id = @jobId OUTPUT
IF (@@ERROR <> 0 OR @ReturnCode <> 0) GOTO QuitWithRollback
/****** Object: Step [RUN MONITOR] Script Date: 5/15/2015 11:01:29 AM ******/
EXEC @ReturnCode = msdb.dbo.sp_add_jobstep @job_id=@jobId, @step_name=N'RUN MONITOR',
@step_id=1,
@cmdexec_success_code=0,
@on_success_action=1,
@on_success_step_id=0,
@on_fail_action=2,
@on_fail_step_id=0,
@retry_attempts=0,
@retry_interval=0,
@os_run_priority=0, @subsystem=N'CmdExec',
@command=N'powershell “D:\FOLDER\POWERSCRIPT.ps1″',
@flags=0
@command=N'powershell “D:\FOLDER\POWERSCRIPT.ps1″',
这里的引号看起来不对。您应该删除它们并将它们重新键入为双引号,如下所示:
@command=N'powershell "D:\FOLDER\POWERSCRIPT.ps1"',
你能看出区别吗?复制和粘贴值时有时会发生这种情况。