Further PowerShell scripts to manage Windows Services

Following on from the previous post I published on remotely managing Windows Services with PowerShell I thought it would be useful to add some extra scripts that you can use to work with Windows Services.

GET DETAILS FOR A WINDOWS SERVICE
Get-Service -Name [INSERT_SERVICE_NAME]  -ComputerName [INSERT_COMPUTER_NAME]  | Format-Table –AutoSize

Example:

Get-Service -Name Jonathan.Welch.Test.Service  -ComputerName jon-app-01 | Format-Table –AutoSize
GET DETAILS FOR WINDOWS SERVICE THAT MATCH SUPPLIED NAME CRITERIA
Get-Service -Name [INSERT_PART_OF_SERVICE_NAME]*  -ComputerName [INSERT_COMPUTER_NAME]  | Format-Table –AutoSize

Example:
This script will find all services that start with Jonathan.Welch

Get-Service -Name Jonathan.Welch*  -ComputerName jon-app-01 | Format-Table –AutoSize
GET DETAILS FOR A WINDOWS SERVICE ON MULTIPLE SERVERS
$computers = @("[INSERT_COMPUTER_NAME_1]", "[INSERT_COMPUTER_NAME_2]")
Get-Service -Name [INSERT_SERVICE_NAME]  -ComputerName $computers | Select MachineName, Name, Status | Sort MachineName, Name | Format-Table –AutoSize

Example:

$computers = @("jon-app-01", "jon-app-02")
Get-Service -Name Jonathan.Welch.Test.Service  -ComputerName $computers | Select MachineName, Name, Status | Sort MachineName, Name | Format-Table –AutoSize
WRITE A COMMENT TO CONSOLE
#Hello World!

SQL Server – Discover tables that are replicated

Here are some useful SQL Scripts to get the details of what tables are included in replication in the database the query is connected to.

SELECT		*
FROM		sys.tables
WHERE		is_replicated = 1
ORDER BY	name

The script below will provide extra details on the subscriptions.

SELECT		publisher=sysservers.srvname, 
		subscriber_db=dest_db, 
		Subscriber=syssubscriptions.srvname, 
		article_name=sysarticles.name,
		syspublications.name AS PublicationName
FROM		syssubscriptions 
JOIN		sysarticles 
ON		syssubscriptions.artid=sysarticles.artid
JOIN		master.dbo.sysservers 
ON		syssubscriptions.srvid =sysservers.srvid
JOIN		syspublications 
ON		syspublications.PubId = sysarticles.pubid
ORDER BY	article_name

Additionally you could use the query below to find replication details for a specific table. The example is checking the Customer table

SELECT		P.name Publication,
		A.name TableName,
		A.dest_table DestinationTable 
FROM		syspublications P 
INNER JOIN	sysarticles A ON P.pubid = A.pubid
WHERE		A.name ='Customer'