functions/get-d365label.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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
<# .SYNOPSIS Get label from the label file from Dynamics 365 Finance & Operations environment .DESCRIPTION Get label from the label file from the running the Dynamics 365 Finance & Operations instance .PARAMETER BinDir The path to the bin directory for the environment Default path is the same as the AOS service PackagesLocalDirectory\bin Default value is fetched from the current configuration on the machine .PARAMETER LabelFileId Name / Id of the label "file" that you want to work against .PARAMETER Language Name / string representation of the language / culture you want to work against Default value is "en-US" .PARAMETER Name Name of the label that you are looking for Accepts wildcards for searching. E.g. -Name "@PRO59*" Default value is "*" which will search for all labels .EXAMPLE PS C:\> Get-D365Label -LabelFileId PRO Shows the entire list of labels that are available from the PRO label file. The language is defaulted to "en-US". .EXAMPLE PS C:\> Get-D365Label -LabelFileId PRO -Language da Shows the entire list of labels that are available from the PRO label file. Shows only all "da" (Danish) labels. .EXAMPLE PS C:\> Get-D365Label -LabelFileId PRO -Name "@PRO59*" Shows the labels available from the PRO label file where the name fits the search "@PRO59*" A result set example: Name Value Language ---- ----- -------- @PRO59 Indicates if the type of the rebate value. en-US @PRO594 Pack consumption en-US @PRO595 Pack qty now being released to production in the BOM unit. en-US @PRO596 Pack unit. en-US @PRO597 Pack proposal for release in the packing unit. en-US @PRO590 Constant pack qty en-US @PRO593 Pack proposal release in BOM unit. en-US @PRO598 Pack quantity now being released for the production in the packing unit. en-US .EXAMPLE PS C:\> Get-D365Label -LabelFileId PRO -Name "@PRO59*" -Language da,en-us Shows the labels available from the PRO label file where the name fits the search "@PRO59*". Shows for both "da" (Danish) and en-US (English) .NOTES Tags: PackagesLocalDirectory, Servicing, Language, Labels, Label Author: Mötz Jensen (@Splaxi) This cmdlet is inspired by the work of "Pedro Tornich" (twitter: @ptornich) All credits goes to him for showing how to extract these information His github repository can be found here: https://github.com/ptornich/LabelFileGenerator #> function Get-D365Label { [CmdletBinding(DefaultParameterSetName = 'Default')] param ( [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 1 )] [string] $BinDir = "$Script:BinDir\bin", [Parameter(Mandatory = $true, ParameterSetName = 'Default', ValueFromPipelineByPropertyName = $true, Position = 2 )] [string] $LabelFileId, [Parameter(Mandatory = $false, ParameterSetName = 'Default', ValueFromPipelineByPropertyName = $true, Position = 3 )] [string[]] $Language = "en-US", [Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 4 )] [string] $Name = "*" ) begin { } process { $files = @((Join-Path -Path $BinDir -ChildPath "Microsoft.Dynamics.AX.Xpp.AxShared.dll")) if (-not (Test-PathExists -Path $files -Type Leaf)) { return } Add-Type -Path $files foreach ($item in $Language) { $culture = New-Object System.Globalization.CultureInfo -ArgumentList $item Write-PSFMessage -Level Verbose -Message "Searching for label" -Target $culture $labels = [Microsoft.Dynamics.Ax.Xpp.LabelHelper]::GetAllLabels($LabelFileId, $culture) foreach ($itemLabel in $labels) { foreach ($key in $itemLabel.Keys) { if ($key -notlike $Name) { continue } [PSCustomObject]@{ Name = $Key Value = $itemLabel[$key] Language = $item PSTypeName = 'D365FO.TOOLS.Label' } } } } } end { } } |