Technical Article

Check running SQL Services

,

Add host details (machines names) to a test file.

Compile the function

Run the function: RunningSQLServices

## Execute the function.
 RunningSQLServices 'c:\hostname.txt' 'c:\reporttab.txt'
Function RunningSQLServices
{

[CmdletBinding()]
    Param
    (
        [Parameter(Position=0,Mandatory=$true)][string]$filepath #Enter filename containing server names with single quotes
      , [Parameter(Position=1,Mandatory=$true)][string]$outfile  #Enter path with single quotes (The file will be recreated if you use the same output file.)           
    )

Process
{
 $result=@()
 

ForEach ($objitem in get-content $filepath) {
 $result += $objitem |out-file $outfile
 $result += get-service -ComputerName $objitem -displayname *SQL*| Where-Object {$_.status -eq "Running"}| Select-Object Machinename, Status,Name,DisplayName  | format-table -auto -wrap -force 
 }
 
#$result | export-csv $outfile -Delimiter "|" -NoTypeInformation
$result | out-file $outfile

#$result | Export-CSV $outfile -Append
#$result | Export-Csv -Path 'C:\service_status1.txt' -Delimiter ';' –notype
#$result |export-csv -delimiter "$" -path $outfile

}
}

## Execute the function.
 RunningSQLServices 'c:\hostname.txt' 'c:\reporttab.txt'

Rate

3 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

3 (2)

You rated this post out of 5. Change rating