powershell error


hey tech bros,

not sure whether right forum.i error while executing job status report script.

#create new excel object using com   $excel = new-object -comobject excel.application  $excel.visible = $true    $excel = $excel.workbooks.add()  $sheet = $excel.worksheets.item(1)    #counter variable rows  $introw = 1    #read thru contents of sql_servers.txt file  foreach ($instance in get-content "c:\sqlcheck\serverlist.txt")  {         #create column headers       $sheet.cells.item($introw,1) = "instance name:"       $sheet.cells.item($introw,2) = $instance       $sheet.cells.item($introw,1).font.bold = $true       $sheet.cells.item($introw,2).font.bold = $true         $introw++          $sheet.cells.item($introw,1) = "job name"        $sheet.cells.item($introw,2) = "last run outcome"        $sheet.cells.item($introw,3) = "last run date"         #format column headers       ($col = 1; $col –le 3; $col++)       {            $sheet.cells.item($introw,$col).font.bold = $true            $sheet.cells.item($introw,$col).interior.colorindex = 48            $sheet.cells.item($introw,$col).font.colorindex = 34       }         $introw++        #######################################################       #this script gets sql server agent job status information using powershell         [system.reflection.assembly]::loadwithpartialname('microsoft.sqlserver.smo') | out-null         # create smo connection instance       $srv = new-object ('microsoft.sqlserver.management.smo.server') $instance         $jobs=$srv.jobserver.jobs -like "tcb*"         #formatting using excel            foreach ($job in $jobs)    {            # formatting failed jobs          if ($job.lastrunoutcome -eq 0)          {              $fgcolor = 3          }          else          {              $fgcolor = 0          }                 $sheet.cells.item($introw, 1) =  $job.name          $sheet.cells.item($introw, 2) = $job.lastrunoutcome.tostring()          $sheet.cells.item($introw, 2).interior.colorindex = $fgcolor          $sheet.cells.item($introw, 3) =  $job.lastrundate                               $introw ++        }      $introw ++       }    $sheet.usedrange.entirecolumn.autofit()  cls    



best regards, arun http://whynotsql.blogspot.com/

hi arun,

i hope running right server names in c:\sqlcheck\serverlist.txt. giving wrong servername in input file resulted in null output. can't convert null value expression.

and run script powershell-ise better handling , execution. 

-prashanth





SQL Server  >  SQL Server Database Engine



Comments

Popular posts from this blog

Conditional formatting a graph vertical axis in SSRS 2012 charts

Register with Power BI failed

SQL server replication error Cannot find the dbo or user defined function........