functions/get-d365model.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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
<# .SYNOPSIS Get available model from Dynamics 365 Finance & Operations environment .DESCRIPTION Get available model from the machine running the AOS service for Dynamics 365 Finance & Operations .PARAMETER Name Name of the model that you are looking for Accepts wildcards for searching. E.g. -Name "Application*Adaptor" Default value is "*" which will search for all models .PARAMETER Module Name of the module that you want to list models from Accepts wildcards for searchinf. E.g. -Module "Application*Adaptor" Default value is "*" which will search across all modules .PARAMETER CustomizableOnly Instructs the cmdlet to filter out all models that cannot be customized .PARAMETER ExcludeMicrosoftModels Instructs the cmdlet to exclude all models that has Microsoft as the publisher from the output .PARAMETER ExcludeBinaryModels Instruct the cmdlet to exclude binary models from the output .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 PackageDirectory Path to the directory containing the installed package / module Default path is the same as the AOS service "PackagesLocalDirectory" directory Default value is fetched from the current configuration on the machine .EXAMPLE PS C:\> Get-D365Model Shows the entire list of installed models located in the default location on the machine. A result set example: ModelName Module IsBinary Customization Id Publisher --------- ------ -------- ------------- -- --------- AccountsPayableMobile AccountsPayableMobile False DoNotAllow 895571380 Microsoft Corporation ApplicationCommon ApplicationCommon False DoNotAllow 8956718 Microsoft ApplicationFoundation ApplicationFoundation False Allow 450 Microsoft Corporation IsvFoundation IsvFoundation True Allow 895972027 Isv Corp IsvLicense IsvLicense True DoNotAllow 895972028 Isv Corp .EXAMPLE PS C:\> Get-D365Model -CustomizableOnly Shows only the models that are marked as customizable. Will only include models that is Customization = "Allow". A result set example: ModelName Module IsBinary Customization Id Publisher --------- ------ -------- ------------- -- --------- ApplicationFoundation ApplicationFoundation False Allow 450 Microsoft Corporation ApplicationPlatform ApplicationPlatform False Allow 400 Microsoft Corporation ApplicationPlatformFormAdaptor ApplicationPlatformFormAdaptor False Allow 855030 Microsoft Corporation IsvFoundation IsvFoundation True Allow 895972027 Isv Corp .EXAMPLE PS C:\> Get-D365Model -ExcludeMicrosoftModels Shows only the models that doesn't have "Microsoft" in the publisher. Will only include models that is Publisher -NotLike "Microsoft*". A result set example: ModelName Module IsBinary Customization Id Publisher --------- ------ -------- ------------- -- --------- IsvFoundation IsvFoundation True Allow 895972027 Isv Corp IsvLicense IsvLicense True DoNotAllow 895972028 Isv Corp .EXAMPLE PS C:\> Get-D365Model -ExcludeBinaryModels Shows only the models that are NOT binary. Will only include models that is IsBinary = "False". A result set example: ModelName Module IsBinary Customization Id Publisher --------- ------ -------- ------------- -- --------- AccountsPayableMobile AccountsPayableMobile False DoNotAllow 895571380 Microsoft Corporation ApplicationCommon ApplicationCommon False DoNotAllow 8956718 Microsoft ApplicationFoundation ApplicationFoundation False Allow 450 Microsoft Corporation .EXAMPLE PS C:\> Get-D365Model -CustomizableOnly -ExcludeMicrosoftModels Shows only the models that are marked as customizable and NOT from Microsoft. Will only include models that is Customization = "Allow". Will only include models that is Publisher -NotLike "Microsoft*". A result set example: ModelName Module IsBinary Customization Id Publisher --------- ------ -------- ------------- -- --------- IsvFoundation IsvFoundation True Allow 895972027 Isv Corp .EXAMPLE PS C:\> Get-D365Model -Name "Application*Adaptor" Shows the list of models where the name fits the search "Application*Adaptor". A result set example: ModelName Module IsBinary Customization Id Publisher --------- ------ -------- ------------- -- --------- ApplicationFoundationFormAd... ApplicationFoundationFormAd... False DoNotAllow 855029 Microsoft Corporation ApplicationPlatformFormAdaptor ApplicationPlatformFormAdaptor False Allow 855030 Microsoft Corporation ApplicationSuiteFormAdaptor ApplicationSuiteFormAdaptor False DoNotAllow 855028 Microsoft Corporation ApplicationWorkspacesFormAd... ApplicationWorkspacesFormAd... False DoNotAllow 855066 Microsoft Corporation .EXAMPLE PS C:\> Get-D365Model -Module ApplicationSuite Shows only the models that are inside the ApplicationSuite module. A result set example: ModelName Module IsBinary Customization Id Publisher --------- ------ -------- ------------- -- --------- Electronic Reporting Applic... ApplicationSuite False DoNotAllow 855009 Microsoft Corporation Foundation ApplicationSuite False DoNotAllow 17 Microsoft Corporation SCMControls ApplicationSuite False DoNotAllow 855891 Microsoft Corporation Tax Books Application Suite... ApplicationSuite False DoNotAllow 895570102 Microsoft Corporation Tax Engine Application Suit... ApplicationSuite False DoNotAllow 8957001 Microsoft Corporation .EXAMPLE PS C:\> Get-D365Model -Name "*Application*" -Module "*Suite*" Shows the list of models where the name fits the search "*Application*" and the module name fits the search "*Suite*". A result set example: ModelName Module IsBinary Customization Id Publisher --------- ------ -------- ------------- -- --------- ApplicationSuiteFormAdaptor ApplicationSuiteFormAdaptor False DoNotAllow 855028 Microsoft Corporation AtlApplicationSuite AtlApplicationSuite False DoNotAllow 895972466 Microsoft Corporation Electronic Reporting Applic... ApplicationSuite False DoNotAllow 855009 Microsoft Corporation Tax Books Application Suite... ApplicationSuite False DoNotAllow 895570102 Microsoft Corporation Tax Engine Application Suit... ApplicationSuite False DoNotAllow 8957001 Microsoft Corporation .NOTES Tags: PackagesLocalDirectory, Servicing, Model, Models, Module, Modules Author: Mötz Jensen (@Splaxi) The cmdlet supports piping and can be used in advanced scenarios. See more on github and the wiki pages. #> function Get-D365Model { [CmdletBinding()] param ( [string] $Name = "*", [Parameter(ValueFromPipelineByPropertyName = $true)] [Alias("ModuleName")] [string] $Module = "*", [switch] $CustomizableOnly, [switch] $ExcludeMicrosoftModels, [switch] $ExcludeBinaryModels, [string] $BinDir = "$Script:BinDir\bin", [string] $PackageDirectory = $Script:PackageDirectory ) begin { [System.Collections.ArrayList] $Files2Process = New-Object -TypeName "System.Collections.ArrayList" $null = $Files2Process.Add((Join-Path $BinDir "Microsoft.Dynamics.AX.Metadata.Management.Delta.dll")) $null = $Files2Process.Add((Join-Path $BinDir "Microsoft.Dynamics.AX.Metadata.Management.Diff.dll")) $null = $Files2Process.Add((Join-Path $BinDir "Microsoft.Dynamics.AX.Metadata.Management.Merge.dll")) $null = $Files2Process.Add((Join-Path $BinDir "Microsoft.Dynamics.AX.Metadata.Management.Core.dll")) $null = $Files2Process.Add((Join-Path $BinDir "Microsoft.Dynamics.AX.Metadata.dll")) $null = $Files2Process.Add((Join-Path $BinDir "Microsoft.Dynamics.AX.Metadata.Core.dll")) $null = $Files2Process.Add((Join-Path $BinDir "Microsoft.Dynamics.AX.Metadata.Storage.dll")) $null = $Files2Process.Add((Join-Path $BinDir "Microsoft.Dynamics.ApplicationPlatform.XppServices.Instrumentation.dll")) Import-AssemblyFileIntoMemory -Path $($Files2Process.ToArray()) Write-PSFMessage -Level Verbose -Message "Intializing RuntimeProvider." $runtimeProviderConfiguration = New-Object Microsoft.Dynamics.AX.Metadata.Storage.Runtime.RuntimeProviderConfiguration -ArgumentList $Script:PackageDirectory $metadataProviderFactoryViaRuntime = New-Object Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory $metadataProviderViaRuntime = $metadataProviderFactoryViaRuntime.CreateRuntimeProvider($runtimeProviderConfiguration) Write-PSFMessage -Level Verbose -Message "MetadataProvider initialized." -Target $metadataProviderViaRuntime $models = $metadataProviderViaRuntime.ModelManifest.ListModelInfos() $models | ForEach-Object { $_ | Add-Member -MemberType NoteProperty -Name 'IsBinary' -Value $false } Write-PSFMessage -Level Verbose -Message "Testing if the cmdlet is running on a OneBox or not." -Target $Script:IsOnebox if ($Script:IsOnebox) { Write-PSFMessage -Level Verbose -Message "Machine is onebox. Initializing DiskProvider too." $diskProviderConfiguration = New-Object Microsoft.Dynamics.AX.Metadata.Storage.DiskProvider.DiskProviderConfiguration $diskProviderConfiguration.AddMetadataPath($PackageDirectory) $metadataProviderFactoryViaDisk = New-Object Microsoft.Dynamics.AX.Metadata.Storage.MetadataProviderFactory $metadataProviderViaDisk = $metadataProviderFactoryViaDisk.CreateDiskProvider($diskProviderConfiguration) Write-PSFMessage -Level Verbose -Message "MetadataProvider initialized." -Target $metadataProviderViaDisk $diskModels = $metadataProviderViaDisk.ModelManifest.ListModelInfos() foreach($model in $models) { if ($diskModels.Name -NotContains $model.Name) { $model.IsBinary = $true } } } if ($CustomizableOnly) { $models = $models | Where-Object Customization -eq "Allow" } if($ExcludeBinaryModels -eq $true){ $models = $models | Where-Object IsBinary -eq $false } } process { if (Test-PSFFunctionInterrupt) { return } $modelsLocal = $models $modelsLocal = $modelsLocal | Where-Object Module -like $Module Write-PSFMessage -Level Verbose -Message "Looping through all models." foreach ($obj in $($modelsLocal | Sort-Object Name, Module)) { Write-PSFMessage -Level Verbose -Message "Filtering out all models that doesn't match the model search." -Target $obj if ($obj.Name -NotLike $Name) { continue } if ($ExcludeMicrosoftModels -and $obj.Publisher -like "Microsoft*") { continue } $obj | Select-PSFObject "Name as ModelName", * -ExcludeProperty Name -TypeName "D365FO.TOOLS.ModelInfo" } } } |