functions/get-axaosinstance.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
50
51
52
53
54
<#
.SYNOPSIS
Get AX 2012 AOS Instance
 
.DESCRIPTION
Get AX 2012 AOS Instance details from the local machine
 
.PARAMETER Name
The search string to filter the AOS instance that you're looking for
 
The parameter supports wildcards. E.g. -Name "*DEV*"
 
Default value is "*" and will give you all the instances
 
.PARAMETER InstanceNo
The search string to filter the AOS instance that you're looking for
 
The parameter supports wildcards. E.g. -InstanceNo "*1*"
 
Default value is "*" and will give you all the instances
 
.EXAMPLE
Get-AxAosInstance
 
This will get you all the installed AX 2012 AOS instances on the machine
 
.NOTES
Author: Mötz Jensen (@Splaxi)
 
#>

function Get-AxAosInstance {
    [CmdletBinding()]
    Param(
        [Parameter()]
        [string] $Name = "*",
        
        [Parameter()]
        [string] $InstanceNo = "*"
    )
    $Instances = Get-ChildItem -Path $Script:RegistryAos
        
    $res = New-Object System.Collections.ArrayList 
    
    $Instances | ForEach-Object {                
        $null = $res.Add((Get-AxAosInstanceDetails $_.Name))
    }

    foreach ($obj in $res) {
        if ($obj.InstanceName -NotLike $Name) { continue }
        if ($obj.InstanceNumber -NotLike $InstanceNo) { continue }

        $obj
    }
}