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:
SELECT HOST_NAME() AS HostName, APP_NAME() AS ApplicationName;
On my system, that returns:

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 where they were 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:
![]()
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.
![]()
However, note that if you use the –Hostname option, it actually sets the Application Name and does not set the Host Name:
![]()
I really wish it wasn’t like this but it is what it is. Instead, I’ve included a picture of a cute dog that’s really puzzled. Thanks for taking it and putting it on Unsplash Michelle Tresemer.
2026-06-27