|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Monday, November 02, 2009 9:41 AM
Points: 75,
Visits: 124
|
|
I typed the following code that I found on the Internet on my local machine using Notepad and I save it giving it an extention of PS1. Then I copied the file on the remote sql server machine. I also mapped to that drive (where I placed the file) on my local machine and I typed Set-ExecutionPolicy in PowerShell. When I try to run the script in Powershell it tells me it is not a script. What I am doing wrong?
[void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo"); [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum"); [void][reflection.assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo");
function GetFailedAgentJobs { param ([string]$servername="127.0.0.1") $srv = new-object('Microsoft.SqlServer.Management.Smo.server') $servername $jobs = $srv.jobserver.jobs | where-object {$_.isenabled} foreach ($job in $jobs) { [int]$outcome = 0 [string]$output = "" ## Did the job fail completely? if ($job.LastRunOutcome -ne "Succeeded") { $outcome++ $output = $output + " Job failed (" + $job.name + ")" + " Result: " + $job.LastRunOutcome } ## Did any of the steps fail? foreach ($step in $job.jobsteps) { if ($step.LastRunOutcome -ne "Succeeded"){ $outcome++ $output = $output + " Step failed (" + $step.name + ")" + " Result: " + $step.LastRunOutcome + " -- " } } if ($outcome -gt 0) { $obj = New-Object Object $obj | Add-Member Noteproperty name -value $job.name $obj | Add-Member Noteproperty lastrundate -value $job.lastrundate $obj | Add-Member Noteproperty lastrunoutcome -value $output $obj } } }
|
|
|
|