![]() ![]() ![]() If you do use dynamic ports, you'll need to factor that in as well. I also never use a dynamic port configuration, so that's not reflected within my script. Otherwise, if it's false (as it is on all my configurations), you'll need some logic to determine which of the other non-loopback endpoints you prefer to use. If ListenOnAll = 1 then IPAll the only endpoint configuration you should use. Write-Error "No SQL Server installation detected." = $Version.GetValue("Version") Įdition = $Version.GetValue("EditionType") Īddress = if ($Socket.PSChildName -eq "IPAll") Īctive = "1" -eq $Socket.GetValue("Active") (Get-Item -Path "$($Sockets.PSPath)\*").PSPath | $ListenOnAll = "1" -eq $Sockets.GetValue("ListenOnAllIPs") $Sockets = Get-Item -Path "$($Instance.PSPath)\MSSQLServer\SuperSocketNetLib\Tcp" $Version = Get-Item -Path "$($Instance.PSPath)\Setup" $Instance = Get-Item -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$InstallationName" $InstallationName = (Get-Item -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL").GetValue($InstanceName) (Get-Item -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL").Property | If (Test-Path -Path "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL") PowerShell isn't hard to read so I'm sure you can figure out what's going on, but at a minimum, the only things you'd likely be interested in are the registry paths contained within: It's a lazy script insofar as I wrote it to be run locally, not remotely, but that's unimportant for your question. I do have to say though - as a disclaimer, while this is related to SQL Server, I'd put it in the "barely" category.Īnyhow, I do have a PowerShell script I use for my own purposes (as I work a lot with Server Core) that lists the endpoint configuration. Rather, you have to look up a few registry keys that act as pointers to other keys, from which you can read the value(s). But it's not as simple as looking up a key-value pair the way you probably expected to using the environment variable approach. Java on Windows can read the registry, and the SQL Server endpoint is configured - and maintained - within the registry, meaning you can actually look up the endpoint configuration. The endpoint configuration is not stored in any environment variables, meaning someone would have to manually add them to the system environment variables table (taking the easiest option), but of course, if SQL Server's reconfigured, or if it's configured to use dynamic ports and those change on a whim, then the whole manual environment variable approach is wasted and you're back to square one. Are ways of using an environment variable, but there's not much value in speaking to them since that undermines what you asked for, which is a way of dynamically obtaining the endpoint configuration(s). ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |