我正在使用下面的代码从运行良好的 SSIS 运行 ssis 作业,但我希望在运行作业后它应该等待作业完成然后继续
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") |Out-Null;
[Microsoft.SqlServer.Management.Smo.Server]$sqlServer = New-Object Microsoft.SqlServer.Management.Smo.Server $HostName;
if([String]::IsNullOrEmpty($sqlServer.Urn))
{
Write-Host "`nThe hostname provided is not a valid SQL Server instance. Did you mistype the alias or forget to add the instance name?`n";
Exit;
}
else
{
[String]$databaseInstance = $sqlServer.JobServer.Urn.Value.Substring($sqlServer.JobServer.Urn.Value.IndexOf("'") + 1, `
$sqlServer.JobServer.Urn.Value.IndexOf("'", ($sqlServer.JobServer.Urn.Value.IndexOf("'")) `
- ($sqlServer.JobServer.Urn.Value.IndexOf("'"))));
}
Write-Host "Enumerating jobs on server ...";
[Microsoft.SqlServer.Management.Smo.Agent.Job]$job = ($sqlServer.JobServer.Jobs | ? { $_.Name -eq $JobName });
if($job -eq $null)
{
Write-Host "`nNo such job on the server.`n";
Exit;
}
# Finally invoke the job. Use the job history (in SSMS) to verify the success of the job.
Write-Host "Executing job (the script doesn't wait for the job to finish but it should)...`n`n";
$job.Start();
*$job.Start(); 之后如何等待 看到工作完成,以便我可以继续进行?
我正在执行下面的代码,但它不能正常工作,有什么帮助吗?
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
$server = new-object "Microsoft.SqlServer.Management.Smo.Server" "ServerName"
$job = $server.JobServer.Jobs["YourJobName"]
$now = Get-Date
do
{
Start-Sleep -Seconds 1
$job.Refresh()
$jobstat = $job | select CurrentRunStatus
$stat = $jobstat.CurrentRunStatus
WRITE-HOST $stat
}
while($stat -eq "Executing")
$job | select Name,CurrentRunStatus,LastRunDate