Finding SQL Servers with PowerShell, Part Deux

Finding SQL Servers with PowerShell, Part Deux

Rate This
  • Comments 1

A reader named "Ben" wrote me and said that he looked at my script in PowerShell that finds SQL Server Instances using the WMI provider yesterday and he came up with another method. Here's what he wrote:

Hi there,

I wasn't able to find a way to post a comment to the blog post, but I was wondering why something like the following code wouldn't be better:

   1: # Replace with your computer, or create a function from the code just below the $machine_name line below:
   2:  
   3: $machine_name = "bwoody1"
   4:  
   5:  
   6: $sql_servers = get-wmiobject -class win32_service -computer $machine_name
   7: $sql_servers | where { $_.name -like 'MSSQL*' -and $_.Description -like '*transaction*'} | select name

 

The advantage that I see is that you don't have to have powershell installed on each machine.  You can have a text file of server names and populate $machine_name through a read of that file. 

Thanks so much for your blog...I really learn a lot from reading it

Sincerely,
Ben

 

Thanks, Ben!  The great thing about PowerShell is that there are so many ways to do similar things, based on your goals. Keep in mind with Ben's approach you'll need to be able to use the WMI provider on the target machine, which has security implications as well as the fact that WMI calls like this might be blocked by your security policies.


As always, this warning applies to any script you find anywhere, including here.

Leave a Comment
  • Please add 2 and 6 and type the answer here:
  • Post
Page 1 of 1 (1 items)