Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.
I’ve been working more with PowerShell lately and ran into a problem I thought would be easy, but it wasn’t. So I decided to blog what I learned.
Assigning a String
I had a string that I wanted to use in a command. In this case, the Start-Service command. Here’s what I wrote:
Start-Service -Name “SQLAgent$$SQL2016_QA”
This didn’t work, mainly because of this error.
PoSh thinks my string is “SQLAgent\”, not “SQLAgent$SQL2016_QA”. That’s strange, at least to me. Let’s try a variable.
OK, I know I need to escape the dollar sign. I ran a quick Google search, because that’s way quicker than looking through documentation and found a piece on escaping strings. It mentions the backtick (`) as the character to use. Let’s try that.
It works. Now to try to start the service.
No error, but it is it running? Yes.
This is a quick look at string work in PoSh. The more I try to automate work and get things to run themselves, the handier I find PoSh. Since I tend to work with named instances, this was valuable.
#SQLNewBlogger
This was one of those items that I spent about 5-10 minutes figuring out and then another 10 minutes shooting screens and duplicating my work. The writeup was easy, and it will help me remember how to do that in the future.
Filed under: Blog Tagged: powershell, SQLNewBlogger, syndicated
![]()