Skip to content

Commit

Permalink
Update Discover-MSSQLServers.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
PyroTek3 committed Aug 31, 2014
1 parent e83ee6a commit 83e8839
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions Discover-MSSQLServers.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ License: BSD 3-Clause
Required Dependencies: None
Optional Dependencies: None
Version: 1.0
Version: 1.1
.DESCRIPTION
This script is used to discover Microsoft SQL servers in the Active Directory Forest.
Expand All @@ -24,6 +24,8 @@ Currently, the script performs the following actions:
* Displays the Microsoft SQL server FQDNs ports and instances
* Also displays additional computer information if ExtendedInfo is enabled.
REQUIRES: Active Directory user authentication. Standard user access is fine - admin access is not necessary.
.PARAMETER ExtendedInfo
Switch: Displays additional information including Operating System, Last Bootup Time (derived from LastLogonTimeStamp), OS Version, and Description.
Operating system properties are populated at first bot-up after joining the domain.
Expand Down Expand Up @@ -138,6 +140,7 @@ ForEach ($AllADSQLServerSPNsItem in $AllADSQLServerSPNs)
Write-Verbose "Loop through the discovered MS SQL SPNs and build the report "
###
$ALLSQLServerReport = $NULL
$AllMSSQLServerFQDNs = $NULL
ForEach ($AllMSSQLSPNsItem in $AllMSSQLSPNHashTable.GetEnumerator())
{
$AllMSSQLSPNsItemServerDomainName = $NULL
Expand Down Expand Up @@ -184,27 +187,31 @@ ForEach ($AllMSSQLSPNsItem in $AllMSSQLSPNHashTable.GetEnumerator())

IF ($ExtendedInfo -eq $True)
{
$ADComputerSearch = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$ADComputerSearch.SearchRoot = $AllMSSQLSPNsItemServerDomainLDAPDN
$ADComputerSearch.PageSize = 500
$ADComputerSearch.Filter = "(&(objectCategory=Computer)(name=$AllMSSQLSPNsItemServerName))"
$ComputerADInfo = $ADComputerSearch.FindAll()
TRY
{
$ADComputerSearch = New-Object DirectoryServices.DirectorySearcher([ADSI]"")
$ADComputerSearch.SearchRoot = $AllMSSQLSPNsItemServerDomainLDAPDN
$ADComputerSearch.PageSize = 500
$ADComputerSearch.Filter = "(&(objectCategory=Computer)(name=$AllMSSQLSPNsItemServerName))"
$ComputerADInfo = $ADComputerSearch.FindAll()

[string]$ComputerADDescription = ($ComputerADInfo.properties.description)
[string]$ComputerADInfoOperatingSystem = ($ComputerADInfo.properties.operatingsystem)
[string]$ComputerADInfoOperatingSystemServicePack = ($ComputerADInfo.properties.operatingsystemservicepack)
[string]$ComputerADInfoOperatingSystemVersion = ($ComputerADInfo.properties.operatingsystemversion)

[string]$ComputerADInfoLastLogonTimestamp = ($ComputerADInfo.properties.lastlogontimestamp)
TRY { [datetime]$ComputerADInfoLLT = [datetime]::FromFileTime($ComputerADInfoLastLogonTimestamp) }
CATCH { }
[string]$ComputerADDescription = ($ComputerADInfo.properties.description)
[string]$ComputerADInfoOperatingSystem = ($ComputerADInfo.properties.operatingsystem)
[string]$ComputerADInfoOperatingSystemServicePack = ($ComputerADInfo.properties.operatingsystemservicepack)
[string]$ComputerADInfoOperatingSystemVersion = ($ComputerADInfo.properties.operatingsystemversion)

[string]$ComputerADInfoLastLogonTimestamp = ($ComputerADInfo.properties.lastlogontimestamp)
TRY { [datetime]$ComputerADInfoLLT = [datetime]::FromFileTime($ComputerADInfoLastLogonTimestamp) }
CATCH { }

$SQLServerReport | Add-Member -MemberType NoteProperty -Name OperatingSystem -Value $ComputerADInfoOperatingSystem
$SQLServerReport | Add-Member -MemberType NoteProperty -Name OSServicePack -Value $ComputerADInfoOperatingSystemServicePack
$SQLServerReport | Add-Member -MemberType NoteProperty -Name LastBootup -Value $ComputerADInfoLLT
$SQLServerReport | Add-Member -MemberType NoteProperty -Name OSVersion -Value $ComputerADInfoOperatingSystemVersion
$SQLServerReport | Add-Member -MemberType NoteProperty -Name Description -Value $ComputerADDescription
}
$SQLServerReport | Add-Member -MemberType NoteProperty -Name OperatingSystem -Value $ComputerADInfoOperatingSystem
$SQLServerReport | Add-Member -MemberType NoteProperty -Name OSServicePack -Value $ComputerADInfoOperatingSystemServicePack
$SQLServerReport | Add-Member -MemberType NoteProperty -Name LastBootup -Value $ComputerADInfoLLT
$SQLServerReport | Add-Member -MemberType NoteProperty -Name OSVersion -Value $ComputerADInfoOperatingSystemVersion
$SQLServerReport | Add-Member -MemberType NoteProperty -Name Description -Value $ComputerADDescription
}
CATCH { Write-Warning "Unable to gather properties for computer $AllMSSQLSPNsItemServerName" }
}

[array]$ALLSQLServerReport += $SQLServerReport
}
Expand Down

0 comments on commit 83e8839

Please sign in to comment.