# Step 1 - get the information you need, display them on the
console
PS C:\>
gwmi win32_service
|?{$_.DisplayName
-match "SQL"}
| ft SystemName,
DisplayName,
StartMode,State,StartName -auto
# Step 2 - get all of the required information into a SQL
Server table
# First, we need to create a SQL Server table in SSMS
<#
USE [MyTestDB]
GO
CREATE TABLE [dbo].[ServiceInfo](
       [ServerName]
[varchar](200) NULL,
       [DisplayName]
[varchar](200) NULL,
       [StartMode]
[varchar](20) NULL,
       [StartName]
[varchar](200) NULL
)
#>
# Then we use the following script to populate the data into
the table. It's better to use ISE to take advantage of the intellisense (for ISE
3.0 and 4.0)
$a=
"Localhost","Xu-Acer-PC"
#$a=get-content C:\Servers.txt #Another way if you like to
keep the servers in a text file
$a | % {`
        $ServerName
= $_;
        gwmi win32_service -ComputerName
$ServerName |?{$_.DisplayName -match
"SQL"} |
% { `
                                                                                         
$DisplayName=$_.DisplayName;
                                                                                         
$StartMode=$_.StartMode;
                                                                                         
$StartName=$_.StartName;
                                                                                         
Invoke-Sqlcmd -ServerInstance
$ServerName -Database
"MyTestDB" -Query "Insert ServiceInfo
Select'$ServerName', '$DisplayName','$StartMode','$StartName'"
                                                                                        
}
        }
 
