@@ -270,7 +270,7 @@ Function Get-SQLConnectionTest
270270 [string]$IPAddress,
271271
272272 [Parameter(Mandatory = $false,
273- HelpMessage = 'IP Address Range to Audit.')]
273+ HelpMessage = 'IP Address Range In CIDR Format to Audit.')]
274274 [string]$IPRange,
275275
276276 [Parameter(Mandatory = $false,
@@ -301,6 +301,12 @@ Function Get-SQLConnectionTest
301301
302302 Process
303303 {
304+ # Default connection to local default instance
305+ if(-not $Instance)
306+ {
307+ $Instance = $env:COMPUTERNAME
308+ }
309+ # Split Demarkation Start ^
304310 # Parse computer name from the instance
305311 $ComputerName = Get-ComputerNameFromInstance -Instance $Instance
306312
@@ -319,24 +325,20 @@ Function Get-SQLConnectionTest
319325 if (-not $ContainsValid)
320326 {
321327 Write-Warning "Skipping $ComputerName ($IPAddress)"
328+ $null = $TblResults.Rows.Add("$ComputerName","$Instance",'Out of Scope')
322329 return
323330 }
324331 }
325332
326333 if(-not $(Test-Subnet -cidr $IPRange -ip $IPAddress))
327334 {
328335 Write-Warning "Skipping $ComputerName ($IPAddress)"
336+ $null = $TblResults.Rows.Add("$ComputerName","$Instance",'Out of Scope')
329337 return
330338 }
331339 Write-Verbose "$ComputerName ($IPAddress)"
332340 }
333341
334- # Default connection to local default instance
335- if(-not $Instance)
336- {
337- $Instance = $env:COMPUTERNAME
338- }
339-
340342 # Setup DAC string
341343 if($DAC)
342344 {
@@ -447,6 +449,16 @@ Function Get-SQLConnectionTestThreaded
447449 HelpMessage = 'SQL Server instance to connection to.')]
448450 [string]$Instance,
449451
452+ [Parameter(Mandatory = $false,
453+ ValueFromPipeline = $true,
454+ ValueFromPipelineByPropertyName = $true,
455+ HelpMessage = 'IP Address of SQL Server.')]
456+ [string]$IPAddress,
457+
458+ [Parameter(Mandatory = $false,
459+ HelpMessage = 'IP Address Range In CIDR Format to Audit.')]
460+ [string]$IPRange,
461+
450462 [Parameter(Mandatory = $false,
451463 HelpMessage = 'Connect using Dedicated Admin Connection.')]
452464 [Switch]$DAC,
@@ -489,10 +501,15 @@ Function Get-SQLConnectionTestThreaded
489501 if($Instance)
490502 {
491503 $ProvideInstance = New-Object -TypeName PSObject -Property @{
492- Instance = $Instance
504+ Instance = $Instance;
493505 }
494506 }
495507
508+ if($Instance -and $IPAddress)
509+ {
510+ $ProvideInstance | Add-Member -Name "IPAddress" -Value $IPAddress
511+ }
512+
496513 # Add instance to instance list
497514 $PipelineItems = $PipelineItems + $ProvideInstance
498515 }
@@ -509,10 +526,40 @@ Function Get-SQLConnectionTestThreaded
509526 $MyScriptBlock = {
510527 # Setup instance
511528 $Instance = $_.Instance
529+ $IPAddress = $_.IPAddress
512530
513531 # Parse computer name from the instance
514532 $ComputerName = Get-ComputerNameFromInstance -Instance $Instance
515533
534+ if($IPRange -and $IPAddress)
535+ {
536+ if ($IPAddress.Contains(","))
537+ {
538+ $ContainsValid = $false
539+ foreach ($IP in $IPAddress.Split(","))
540+ {
541+ if($(Test-Subnet -cidr $IPRange -ip $IP))
542+ {
543+ $ContainsValid = $true
544+ }
545+ }
546+ if (-not $ContainsValid)
547+ {
548+ Write-Warning "Skipping $ComputerName ($IPAddress)"
549+ $null = $TblResults.Rows.Add("$ComputerName","$Instance",'Out of Scope')
550+ return
551+ }
552+ }
553+
554+ if(-not $(Test-Subnet -cidr $IPRange -ip $IPAddress))
555+ {
556+ Write-Warning "Skipping $ComputerName ($IPAddress)"
557+ $null = $TblResults.Rows.Add("$ComputerName","$Instance",'Out of Scope')
558+ return
559+ }
560+ Write-Verbose "$ComputerName ($IPAddress)"
561+ }
562+
516563 # Setup DAC string
517564 if($DAC)
518565 {
0 commit comments