Skip to content

Commit

Permalink
Merge pull request d365collaborative#3 from d365collaborative/develop…
Browse files Browse the repository at this point in the history
…ment

sync
  • Loading branch information
gertvdh committed Apr 26, 2019
2 parents ce1d7a8 + eb7c892 commit 873a167
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 13 deletions.
2 changes: 1 addition & 1 deletion d365fo.tools/d365fo.tools.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RootModule = 'd365fo.tools.psm1'

# Version number of this module.
ModuleVersion = '0.5.26'
ModuleVersion = '0.5.27'

# ID used to uniquely identify this module
GUID = '7c7b26d4-f764-4cb0-a692-459a0a689dbb'
Expand Down
2 changes: 1 addition & 1 deletion d365fo.tools/d365fo.tools.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$script:ModuleRoot = $PSScriptRoot
$script:ModuleVersion = "0.5.26"
$script:ModuleVersion = "0.5.27"

# Detect whether at some level dotsourcing was enforced
$script:doDotSource = Get-PSFConfigValue -FullName d365fo.tools.Import.DoDotSource -Fallback $false
Expand Down
57 changes: 51 additions & 6 deletions d365fo.tools/functions/get-d365module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,37 @@
Accepts wildcards for searching. E.g. -Name "Application*Adaptor"
Default value is "*" which will search for all packages / modules
.PARAMETER Expand
Adds the version of the package / module to the output
.EXAMPLE
PS C:\> Get-D365Module
Shows the entire list of installed packages / modules located in the default location on the machine
Shows the entire list of installed packages / modules located in the default location on the machine.
.EXAMPLE
PS C:\> Get-D365Module -Expand
Shows the entire list of installed packages / modules located in the default location on the machine.
Will include the file version for each package / module.
.EXAMPLE
PS C:\> Get-D365Module -Name "Application*Adaptor"
Shows the list of installed packages / modules where the name fits the search "Application*Adaptor"
Shows the list of installed packages / modules where the name fits the search "Application*Adaptor".
A result set example:
ApplicationFoundationFormAdaptor
ApplicationPlatformFormAdaptor
ApplicationSuiteFormAdaptor
ApplicationWorkspacesFormAdaptor
.EXAMPLE
PS C:\> Get-D365Module -Name "Application*Adaptor" -Expand
Shows the list of installed packages / modules where the name fits the search "Application*Adaptor".
Will include the file version for each package / module.
.EXAMPLE
PS C:\> Get-D365Module -PackageDirectory "J:\AOSService\PackagesLocalDirectory"
Expand All @@ -68,7 +83,10 @@ function Get-D365Module {
[string] $PackageDirectory = $Script:PackageDirectory,

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

[Parameter(Mandatory = $false, ParameterSetName = 'Default', Position = 4 )]
[switch] $Expand
)

[System.Collections.ArrayList] $Files2Process = New-Object -TypeName "System.Collections.ArrayList"
Expand Down Expand Up @@ -112,9 +130,36 @@ function Get-D365Module {
Write-PSFMessage -Level Verbose -Message "Filtering out all modules that doesn't match the model search." -Target $obj
if ($obj.Name -NotLike $Name) {continue}

[PSCustomObject]@{
Module = $obj.Name
References = $obj.References
if ($Expand -eq $true)
{
$modulepath = Join-Path (Join-Path $PackageDirectory $obj.Name) "bin"

if (Test-Path -Path $modulepath -PathType Container)
{
$fileversion = Get-FileVersion -Path (Get-ChildItem $modulepath -Filter "Dynamics.AX.$($obj.Name).dll").FullName
$version = $fileversion.FileVersion
$versionUpdated = $fileversion.FileVersionUpdated
}
else
{
$version = ""
$versionUpdated = ""
}

[PSCustomObject]@{
Module = $obj.Name
References = $obj.References
Version = $version
VersionUpdated = $versionUpdated
}
}
else
{

[PSCustomObject]@{
Module = $obj.Name
References = $obj.References
}
}
}
}
42 changes: 42 additions & 0 deletions d365fo.tools/internal/functions/get-fileversion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

<#
.SYNOPSIS
Get the file version details
.DESCRIPTION
Get the file version details for any given file
.PARAMETER Path
Path to the file that you want to extract the file version details from
.EXAMPLE
PS C:\> Get-FileVersion -Path "C:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\Bin\AxServ32.exe"
This will get the file version details for the AX AOS executable (AxServ32.exe).
.NOTES
Author: Mötz Jensen (@Splaxi)
Inspired by https://blogs.technet.microsoft.com/askpfeplat/2014/12/07/how-to-correctly-check-file-versions-with-powershell/
#>
function Get-FileVersion {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string] $Path
)

if (-not (Test-PathExists -Path $Path -Type Leaf)) { return }

Write-PSFMessage -Level Verbose -Message "Extracting the file properties for: $Path" -Target $Path

$Filepath = Get-Item -Path $Path

[PSCustomObject]@{
FileVersion = $Filepath.VersionInfo.FileVersion
ProductVersion = $Filepath.VersionInfo.ProductVersion
FileVersionUpdated = "$($Filepath.VersionInfo.FileMajorPart).$($Filepath.VersionInfo.FileMinorPart).$($Filepath.VersionInfo.FileBuildPart).$($Filepath.VersionInfo.FilePrivatePart)"
ProductVersionUpdated = "$($Filepath.VersionInfo.ProductMajorPart).$($Filepath.VersionInfo.ProductMinorPart).$($Filepath.VersionInfo.ProductBuildPart).$($Filepath.VersionInfo.ProductPrivatePart)"
}
}
15 changes: 14 additions & 1 deletion d365fo.tools/tests/functions/Get-D365Module.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,25 @@
$parameter.ParameterSets['Default'].ValueFromPipelineByPropertyName | Should -Be $False
$parameter.ParameterSets['Default'].ValueFromRemainingArguments | Should -Be $False
}
It 'Should have the expected parameter Expand' {
$parameter = (Get-Command Get-D365Module).Parameters['Expand']
$parameter.Name | Should -Be 'Expand'
$parameter.ParameterType.ToString() | Should -Be System.Management.Automation.SwitchParameter
$parameter.IsDynamic | Should -Be $False
$parameter.ParameterSets.Keys | Should -Be 'Default'
$parameter.ParameterSets.Keys | Should -Contain 'Default'
$parameter.ParameterSets['Default'].IsMandatory | Should -Be $False
$parameter.ParameterSets['Default'].Position | Should -Be 4
$parameter.ParameterSets['Default'].ValueFromPipeline | Should -Be $False
$parameter.ParameterSets['Default'].ValueFromPipelineByPropertyName | Should -Be $False
$parameter.ParameterSets['Default'].ValueFromRemainingArguments | Should -Be $False
}
}

Describe "Testing parameterset Default" {
<#
Default -
Default -BinDir -PackageDirectory -Name
Default -BinDir -PackageDirectory -Name -Expand
#>
}

Expand Down
40 changes: 36 additions & 4 deletions docs/Get-D365Module.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Get installed package / module from Dynamics 365 Finance & Operations environmen
## SYNTAX

```
Get-D365Module [[-BinDir] <String>] [[-PackageDirectory] <String>] [[-Name] <String>] [<CommonParameters>]
Get-D365Module [[-BinDir] <String>] [[-PackageDirectory] <String>] [[-Name] <String>] [-Expand]
[<CommonParameters>]
```

## DESCRIPTION
Expand All @@ -26,22 +27,38 @@ Get installed package / module from the machine running the AOS service for Dyna
Get-D365Module
```

Shows the entire list of installed packages / modules located in the default location on the machine
Shows the entire list of installed packages / modules located in the default location on the machine.

### EXAMPLE 2
```
Get-D365Module -Expand
```

Shows the entire list of installed packages / modules located in the default location on the machine.
Will include the file version for each package / module.

### EXAMPLE 3
```
Get-D365Module -Name "Application*Adaptor"
```

Shows the list of installed packages / modules where the name fits the search "Application*Adaptor"
Shows the list of installed packages / modules where the name fits the search "Application*Adaptor".

A result set example:
ApplicationFoundationFormAdaptor
ApplicationPlatformFormAdaptor
ApplicationSuiteFormAdaptor
ApplicationWorkspacesFormAdaptor

### EXAMPLE 3
### EXAMPLE 4
```
Get-D365Module -Name "Application*Adaptor" -Expand
```

Shows the list of installed packages / modules where the name fits the search "Application*Adaptor".
Will include the file version for each package / module.

### EXAMPLE 5
```
Get-D365Module -PackageDirectory "J:\AOSService\PackagesLocalDirectory"
```
Expand Down Expand Up @@ -109,6 +126,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Expand
Adds the version of the package / module to the output

```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: 5
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
Expand Down

0 comments on commit 873a167

Please sign in to comment.