functions/get-d365labelold.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118

<#
    .SYNOPSIS
        Get label from the resource file
         
    .DESCRIPTION
        Get label details from the resource file
         
    .PARAMETER FilePath
        The path to resource file that you want to get label details from
         
    .PARAMETER Name
        Name of the label you are looking for
         
        Accepts wildcards for searching. E.g. -Name "@PRO*"
         
        Default value is "*" which will search for all labels in the resource file
         
    .PARAMETER Value
        Value of the label you are looking for
         
        Accepts wildcards for searching. E.g. -Name "*Qty*"
         
        Default value is "*" which will search for all values in the resource file
         
    .PARAMETER IncludePath
        Switch to indicate whether you want the result set to include the path to the resource file or not
         
        Default is OFF - path details will not be part of the output
         
    .EXAMPLE
        PS C:\> Get-D365Label -Path "C:\AOSService\PackagesLocalDirectory\ApplicationSuite\Resources\en-US\PRO.resources.dll"
         
        Will get all labels from the "PRO.resouce.dll" file
         
        The language is determined by the path to the resource file and nothing else
         
    .EXAMPLE
        PS C:\> Get-D365Label -Path "C:\AOSService\PackagesLocalDirectory\ApplicationSuite\Resources\en-US\PRO.resources.dll" -Name "@PRO505"
         
        Will get the label with the name "@PRO505" from the "PRO.resouce.dll" file
         
        The language is determined by the path to the resource file and nothing else
         
    .EXAMPLE
        PS C:\> Get-D365Label -Path "C:\AOSService\PackagesLocalDirectory\ApplicationSuite\Resources\en-US\PRO.resources.dll" -Value "*qty*"
         
        Will get all the labels where the value fits the search "*qty*" from the "PRO.resouce.dll" file
         
        The language is determined by the path to the resource file and nothing else
         
    .EXAMPLE
        PS C:\> Get-D365InstalledPackage -Name "ApplicationSuite" | Get-D365PackageLabelFile -Language "da" | Get-D365Label -value "*batch*" -IncludePath
         
        Will get all the labels, across all label files, for the "ApplicationSuite", where the language is "da" and where the label value fits the search "*batch*".
         
        The path to the label file is included in the output.
         
    .NOTES
        Tags: PackagesLocalDirectory, Label, Labels, Language, Development, Servicing
         
        Author: Mötz Jensen (@Splaxi)
         
        There are several advanced scenarios for this cmdlet. See more on github and the wiki pages.
         
#>

function Get-D365LabelOld {
    [CmdletBinding(DefaultParameterSetName = 'Default')]
    param (
        [Parameter(Mandatory = $true, ParameterSetName = 'Default', ValueFromPipelineByPropertyName = $true, Position = 1 )]
        [Parameter(Mandatory = $true, ParameterSetName = 'Specific', Position = 1 )]
        [Alias('Path')]
        [string] $FilePath,

        [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 2 )]
        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 2 )]
        [string] $Name = "*",

        [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 2 )]
        [Parameter(Mandatory = $false, ParameterSetName = 'Specific', Position = 2 )]
        [string] $Value = "*",

        [switch] $IncludePath
    )

    BEGIN {}

    PROCESS {
        $assembly = [Reflection.Assembly]::LoadFile($FilePath)

        $resNames = $assembly.GetManifestResourceNames()
        $resname = $resNames[0].Replace(".resources", "")
        $resLanguage = $resname.Split(".")[1]

        $resMan = New-Object -TypeName System.Resources.ResourceManager -ArgumentList $resname, $assembly

        $language = New-Object System.Globalization.CultureInfo -ArgumentList "en-US"
        $resources = $resMan.GetResourceSet($language, $true, $true)

        foreach ($obj in $resources) {
            if ($obj.Name -NotLike $Name) { continue }
            if ($obj.Value -NotLike $Value) { continue }
            $res = [PSCustomObject]@{
                Name     = $obj.Name
                Language = $resLanguage
                Value    = $obj.Value
            }

            if ($IncludePath.IsPresent) {
                $res | Add-Member -MemberType NoteProperty -Name 'Path' -Value $FilePath
            }

            $res
        }
    }

    END {}
}