Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

Hey Posh, Are My Services Running? #SQLNewBlogger

$
0
0

A nother post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBlogger s.

In aprevious post, I looked at escaping strings. The reason I needed to do this was that I was trying to do some automatic work with building and starting SQL Server instances. Part of laying the base for this was checking if services are running, and then perhaps taking action, like starting or stopping.

I knew there was a Get-Service command, and ran that. The output from this is much more than I’d like to consume.


Hey Posh, Are My Services Running? #SQLNewBlogger

I’d like to limit this to SQL Server services. I know there is usually an mssqlServer service, but since I tend to use named instances, this doesn’t work. Plus, I don’t want to search for just a particular service. I want all services for SQL Server.

There is a Where-Object command, that allows me to search. There is also a Like option for comparisons. I’ll structure a command like this:

Get-Service | Where-Object ($_.Name Like “SQL*”)

That is less than successful.


Hey Posh, Are My Services Running? #SQLNewBlogger

Why not? Well, PoSh has some syntax requirements and one of them here is that I don’t want parenthesis, I want curly braces. If I change this, things work better.


Hey Posh, Are My Services Running? #SQLNewBlogger

If you’re older like me and don’t necessarily read small print easily, this might be one that catches you for a bit. However, notice that I only have my SQLAgent and system services, not the core database engine. My wildcard needs work.


Hey Posh, Are My Services Running? #SQLNewBlogger

Now I see all my services and I can easily decide if I want to stop, start, restart, etc.

#SQLNewBlogger

This was a quick post. It took me 10 minutes to relearn a few PoSh things and practice and then about 5 minutes to write this.

I’ll remember it, and it shows how I’m building my administrative skills. You should do that as well.


Viewing all articles
Browse latest Browse all 3160

Latest Images

Trending Articles