ps/Modules/Alkami.DevOps.Inventory/Public/Get-ServiceFabricInventory.ps1
2023-05-30 22:51:22 -07:00

67 lines
2.7 KiB
PowerShell

function Get-ServiceFabricInventory {
<#
.SYNOPSIS
Get a PSObject containing categorized packages which represents the assumed list of what is installed on a Fab machine
.EXAMPLE
Get-ServiceFabricInventory
.PARAMETER ComputerName
The name of the computer to inventory
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $false)]
[string]$ComputerName = "localhost"
)
$logLead = (Get-LogLeadName);
$providerStopWatch = [System.Diagnostics.StopWatch]::StartNew()
$SFDictionary = New-Object System.Collections.Specialized.OrderedDictionary
$SFDetails = New-Object System.Collections.Specialized.OrderedDictionary
$serviceFabricPackages = New-Object System.Collections.Specialized.OrderedDictionary
$requiredServiceFabricPackages = New-Object System.Collections.Specialized.OrderedDictionary
if (!(Test-IsServiceFabricServer)) {
Write-Warning "$logLead : Not a service fabric node. Inventory collection will be skipped"
$SFDictionary.Add("ServiceFabric", $null )
return $SFDictionary
}
try {
Import-Module serviceFabric
} catch {
Write-Warning "$logLead : $($_.exception.message)"
$SFDictionary.Add("ServiceFabric", $null )
return $SFDictionary
}
Connect-AlkamiServiceFabricCluster -hostname $ComputerName | Out-Null
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Reading Service Fabric Packages"
$localServiceFabricPackages = (Get-AlkamiServiceFabricApplications);
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Done Reading Service Fabric Packages"
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Determing environment name"
$environmentName = Get-AppSetting "Environment.Name"
$envName = (Format-AlkamiEnvironmentName -name $environmentName);
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Done determing environment name"
# Filter the packages down to the specific environment, and then record the packages.
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Filtering packages"
$environmentPackages = $localServiceFabricPackages | Where-Object { ($null -eq $_.Environment) -or ($_.Environment -eq $envName)}
foreach ($package in $environmentPackages) {
$serviceFabricPackages.Add("$($package.ServiceFabricApplicationName)", $package);
}
$SFDetails.Add("requiredServiceFabricPackages", $requiredServiceFabricPackages)
$SFDetails.Add("Packages", $serviceFabricPackages)
$SFDictionary.Add("ServiceFabric", $SFDetails)
Write-Verbose "$logLead : [$($providerStopWatch.Elapsed)] : Provider Complete"
$providerStopWatch.Stop()
return $SFDictionary
}