The dbatools module's Find-DbaInstance can accept a computer name and return a list of instances on that machine. Is there an equivalent in the SqlServer module that does this? I tried Get-SqlInstance, but it seems to need actual instance names, as opposed to being able to use it for instance discovery. I'd prefer to use dbatools, but the SqlServer module is what I have consistent access to in the current environment.
-
1Which type of scan do you want: WMI or SQL Browser or a specific TCP port or SPN lookup?Charlieface– Charlieface2022-05-30 20:53:36 +00:00Commented May 30, 2022 at 20:53
-
@Charlieface, WMI seems like it would be the most reliable (Browser might be disabled, the port may be something other than 1433, etc.). I am attempting to find every last 'rogue' install of SQL Server as those unknown instances are the most vulnerable (you can't patch them or retire them if you don't even know they exist).Alex Pixley– Alex Pixley2022-05-31 13:27:30 +00:00Commented May 31, 2022 at 13:27
-
Not sure about WMI, maybe look through the code github.com/dataplat/dbatools/blob/development/functions/… Is there any reason you don't want to install DBA Tools, it's pretty easyCharlieface– Charlieface2022-05-31 15:02:17 +00:00Commented May 31, 2022 at 15:02
-
Using dbatools is the ultimate goal, but the rollout is only partially complete and our security software (after an upgrade) has suddenly started labeling dbatools as 'potentially malicious' and blocks it from running, so until that's remedied, it's not an option.Alex Pixley– Alex Pixley2022-05-31 17:46:53 +00:00Commented May 31, 2022 at 17:46
Add a comment
|
1 Answer
There are many good results that dont even depend on the sqlserver module in this article
eg.
$SQLInstances = Invoke-Command -ComputerName "localhost" {
(Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server').InstalledInstances
}
foreach ($sql in $SQLInstances) {
[PSCustomObject]@{
ServerName = $sql.PSComputerName
InstanceName = $sql
}
}
3 Comments
Alex Pixley
Based on this link, I have avoided the method you suggest. I am trying to find every last 'rogue' install of SQL Server as those unknown instances are the most vulnerable (you can't patch them or retire them if you don't even know they exist).
Otter
Have a look at the section labelled
Get-Service cmdlet in the link I mentioned, that uses WMI to some extent, happy to edit my answer if that is your preferred method?Alex Pixley
I worked through the different methods mentioned in the article. I was surprised at how well using
Get-ChildItem addressed this problem and a couple of others I've been dealing with. For what I'm doing, It's even better than SMO.