40 lines
1.5 KiB
PowerShell
40 lines
1.5 KiB
PowerShell
function Get-InstalledPackages {
|
|
<#
|
|
.SYNOPSIS
|
|
Returns a list of package names/versions deployed on the server, whether the installations
|
|
are managed by Chocolatey or Service Fabric.
|
|
.PARAMETER ComputerName
|
|
The host name of the server to get installed packages from.
|
|
#>
|
|
[CmdletBinding()]
|
|
Param(
|
|
[Parameter(Mandatory = $false)]
|
|
[Alias("server")]
|
|
[string]$ComputerName = "localhost"
|
|
)
|
|
|
|
$packages = $null;
|
|
$loglead = (Get-LogLeadName);
|
|
|
|
$isLocalFabServer = ($ComputerName -eq "localhost") -and (Test-IsServiceFabricServer);
|
|
$isRemoteFabServer = ($null -ne (Select-AlkamiFabServers $ComputerName));
|
|
if($isLocalFabServer -or $isRemoteFabServer) {
|
|
# Fetch Service Fabric Packages
|
|
Write-Verbose "$loglead Determined $ComputerName is a Service Fabric server.";
|
|
Connect-AlkamiServiceFabricCluster -hostname $ComputerName;
|
|
$packages = (Get-AlkamiServiceFabricApplications -ComputerName $ComputerName);
|
|
} else {
|
|
# Fetch Chocolatey Packages
|
|
Write-Verbose "$loglead Determined $ComputerName is a Chocolatey managed server.";
|
|
$script = {
|
|
$result = (Get-ChocoState -local);
|
|
|
|
# Return the results in a map so PS doesn't put needless PSComputerName/RunspaceId properties on every package.
|
|
return @{ Result = $result };
|
|
}
|
|
$packages = (Invoke-Command -ComputerName $ComputerName -ScriptBlock $script).Result;
|
|
}
|
|
|
|
return $packages;
|
|
}
|