Created
May 5, 2019 06:11
-
-
Save jessereynolds/c0bf2598cfa701e8e8596292ffa23620 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# site | |
$fact = 'site' | |
Try {$factvalue = $([System.DirectoryServices.ActiveDirectory.ActiveDirectorySite]::GetComputerSite().Name)} | |
Catch {$factvalue = 'unknown'} | |
Write-Host "$fact=$factvalue" | |
# exchange_server | |
$service = 'Microsoft Exchange*' | |
$fact = 'exchange_server' | |
if ((Get-Service -DisplayName "$service" | Measure-Object).Count -gt 5) | |
{$factvalue = 'true'} | |
else | |
{$factvalue = 'false'} | |
Write-Host "$fact=$factvalue" | |
# exchange_server_version | |
if ($factvalue -eq 'true') | |
{ | |
$program = 'Microsoft Exchange Server' | |
$fact = 'exchange_server_version' | |
$x86 = ((Get-ChildItem 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall') | Where-Object { $_.GetValue( 'DisplayName' ) -eq "$program"}) | |
$x64 = ((Get-ChildItem 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall') | Where-Object { $_.GetValue( 'DisplayName' ) -eq "$program"}) | |
if ($x64) | |
{ | |
$factvalue = $x64.GetValue('DisplayVersion') | |
Write-Host "$fact=$factvalue" | |
} | |
elseif ($x86) | |
{ | |
$factvalue = $x86.GetValue('DisplayVersion') | |
Write-Host "$fact=$factvalue" | |
} | |
} | |
# sharepoint_server | |
$service = 'SharePoint*' | |
$fact = 'sharepoint_server' | |
if ((Get-Service -DisplayName "$service" | Measure-Object).Count -gt 5) | |
{$factvalue = 'true'} | |
else | |
{$factvalue = 'false'} | |
Write-Host "$fact=$factvalue" | |
# sharepoint_server_version | |
if ($factvalue -eq 'true') | |
{ | |
$program = 'Microsoft SharePoint Server 2010' | |
$fact = 'sharepoint_server_version' | |
$x86 = ((Get-ChildItem 'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall') | Where-Object { $_.GetValue( 'DisplayName' ) -eq "$program"}) | |
$x64 = ((Get-ChildItem 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall') | Where-Object { $_.GetValue( 'DisplayName' ) -eq "$program"}) | |
if ($x64) | |
{ | |
$factvalue = $x64.GetValue('DisplayVersion') | |
Write-Host "$fact=$factvalue" | |
} | |
elseif ($x86) | |
{ | |
$factvalue = $x86.GetValue('DisplayVersion') | |
Write-Host "$fact=$factvalue" | |
} | |
} | |
# TODO: Update other facts to use this same method for true\false | |
# fips_algorithm_policy_enabled | |
$fact = 'fips_algorithm_policy_enabled' | |
$factvalue = (Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Lsa\FIPSAlgorithmPolicy -Name Enabled).Enabled -eq 1 | |
Write-Host "$fact=$factvalue".ToLower() | |
# interfaceindex is used to determine front_nic_name and front_nic_dns facts | |
$interfaceindex = ((Get-WMIObject Win32_IP4RouteTable -Filter "Destination = '0.0.0.0'" | Sort-Object -Property "Metric1") | Select-Object -First 1).InterfaceIndex | |
# front_nic_name | |
$fact = 'front_nic_name' | |
$factvalue = (Get-WMIObject Win32_NetworkAdapter | Where-Object {$_.InterfaceIndex -eq $interfaceindex}).NetConnectionID | |
Write-Host "$fact=$factvalue" | |
# front_nic_dns | |
$fact = 'front_nic_dns' | |
$factvalue = ((Get-WmiObject Win32_NetworkAdapterConfiguration |Where-Object {$_.InterfaceIndex -eq $interfaceindex} | ForEach-Object {$_.DNSServerSearchOrder}) -Join ',').TrimEnd(',') | |
Write-Host "$fact=$factvalue" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment