Powershell Invoke-Sqlcmd –Hostname Parameter sets the Application Name instead of the Host Name

Two of the parameters in SQL Server connections are the Application Name and the Host Name. You can see these in SQL Server if you execute the following command:

image

I’ve always been a fan of having applications identify themselves in their connection strings. It makes tasks like tracing much easier. The tools supplied with SQL Server do a reasonable job of that as you can see above. But many other tools don’t do such a good job.

I was working at a site today where they are using Powershell to execute commands for monitoring. I noticed that the Powershell commands did not set the Application Name in the connection string when using Invoke-Sqlcmd. Note the following example:

image

I then tried to work out how to set the Application Name. When I checked the documentation for Invoke-Sqlcmd, it shows that the Hostname is set via the SQLCMD option –H, by using the –Hostname parameter.

image

However, note that if you use the –Hostname option, it actually sets the Application Name and does not set the Host Name:

image

5 thoughts on “Powershell Invoke-Sqlcmd –Hostname Parameter sets the Application Name instead of the Host Name”

  1. upvoted – now we are 2 ! come on people – don't sit at the back grumbling that stuff doesn't get fixed, show you care (takes all of 10 seconds) and upvote your pet peeves on connect. Did anyone say JSON support ?

Leave a Reply

Your email address will not be published.