functions/get-d365installedservice.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

<#
    .SYNOPSIS
        Get installed D365 services
         
    .DESCRIPTION
        Get installed Dynamics 365 for Finance & Operations services that are installed on the machine
         
    .PARAMETER Path
        Path to the folder that contains the "InstallationRecords" folder
         
    .EXAMPLE
        PS C:\> Get-D365InstalledService
         
        This will get all installed services on the machine.
         
    .NOTES
        Tags: Services, Servicing, Topology
         
        Author: Mötz Jensen (@Splaxi)
         
#>

function Get-D365InstalledService {
    [CmdletBinding(DefaultParameterSetName = 'Default')]
    param (
        [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 1 )]
        [string] $Path = $Script:InstallationRecordsDir
    )
    
    begin {
    }
    
    process {
        $servicePath = Join-Path $Path "ServiceModelInstallationRecords"

        Write-PSFMessage -Level Verbose -Message "Service installation log path is: $servicePath" -Target $servicePath
        $ServiceFiles = Get-ChildItem -Path $servicePath -Filter "*_current.xml" -Recurse

        foreach ($obj in $ServiceFiles) {
            [PSCustomObject]@{
                ServiceName = ($obj.Name.Split("_")[0])
                Version     = (Select-Xml -XPath "/ServiceModelInstallationInfo/Version" -Path $obj.fullname).Node."#Text"
            }
        }
    }
    
    end {
    }
}