zoukankan      html  css  js  c++  java
  • AX7: Installing deployable packages with Powershell

    Installing deployable packages to an AX 7 environment can often be done just by a few clicks on LCS (as described in Apply a deployable package on a Microsoft Dynamics 365 for Operations system). Unfortunately the situation isn’t always that simple and you may have to install the package manually, using the process explained in Install a deployable package. It consists of quite a few manual steps and where there are repeated manual steps, one should always consider automation.

    I’ve built a few Powershell functions to help with these tasks:

    #region Parameters
    $folder = 'C:Temp'
    $archiveFileName = 'Updates.zip'
    $runbookId = 'MyRunbook1'
    $ErrorActionPreference = 'Stop'
    #endregion
     
    #region Derived values
    $file = Join-Path $folder $archiveFileName
    $runbookFile = Join-Path $folder "$runbookId.xml"
    $extracted = Join-Path $folder ([System.IO.Path]::GetFileNameWithoutExtension($archiveFileName))
    $topologyFile = Join-Path $extracted 'DefaultTopologyData.xml'
    $updateInstaller = Join-Path $extracted 'AXUpdateInstaller.exe'
    #endregion
     
    Function ExtractFiles
    {
        Unblock-File $file
        Expand-Archive -LiteralPath $file -Destination $extracted
    }
     
    Function SetTopologyData
    {
        [xml]$xml = Get-Content $topologyFile
        $machine = $xml.TopologyData.MachineList.Machine
     
        # Set computer name
        $machine.Name = $env:computername
     
        #Set service models
        $serviceModelList = $machine.ServiceModelList
        $serviceModelList.RemoveAll()
     
        $instalInfoDll = Join-Path $extracted 'Microsoft.Dynamics.AX.AXInstallationInfo.dll'
        [void][System.Reflection.Assembly]::LoadFile($instalInfoDll)
     
        $models = [Microsoft.Dynamics.AX.AXInstallationInfo.AXInstallationInfo]::GetInstalledServiceModel()
        foreach ($name in $models.Name)
        {
            $element = $xml.CreateElement('string')
            $element.InnerText = $name
            $serviceModelList.AppendChild($element)
        }
     
        $xml.Save($topologyFile)
    }
     
    Function GenerateRunbook
    {
        $serviceModelFile = Join-Path $extracted 'DefaultServiceModelData.xml'
        & $updateInstaller generate "-runbookId=$runbookId" "-topologyFile=$topologyFile" "-serviceModelFile=$serviceModelFile" "-runbookFile=$runbookFile"
    }
     
    Function ImportRunbook
    {
        & $updateInstaller import "-runbookfile=$runbookFile"
    }
     
    Function ExecuteRunbook
    {
        & $updateInstaller execute "-runbookId=$runbookId"
    }
     
    Function RerunRunbook([int] $step)
    {
        & $updateInstaller execute "-runbookId=$runbookId" "-rerunstep=$step"
    }
     
    Function SetStepComplete([int] $step)
    {
        & $updateInstaller execute "-runbookId=$runbookId" "-setstepcomplete=$step"
    }
     
    Function ExportRunbook
    {
        & $updateInstaller export "-runbookId=$runbookId" "-runbookfile=$runbookFile"
    }

    When you set parameters (such as the name of your package file) and run the script, you can then execute whole process by the following list of function calls:

    ExtractFiles

    SetTopologyData

    GenerateRunbook

    ImportRunbook

    ExecuteRunbook

    If needed, you can also use RerunRunbook and SetStepComplete (e.g. SetStepComplete 10).

    Note that SetTopologyData takes data just from the current machine, but you can borrow the code and modify it, if you need something more sophisticated.

    This should make things a bit easier and reduce unnecessary errors such as mistyped runbook IDs.

  • 相关阅读:
    母函数做的题
    HDU2089 暴力打表
    HDU2036 改革春风吹满地
    HDU1201 水题
    高可用服务 AHAS 在消息队列 MQ 削峰填谷场景下的应用
    Nacos Committers 团队首亮相,发布 0.9.0 版本
    Dubbo Mesh 在闲鱼生产环境中的落地实践
    Watchdogs利用Redis实施大规模挖矿,常见数据库蠕虫如何破?
    阿里在使用一种更灵活的软件集成发布模式
    2019 年,容器技术生态会发生些什么?
  • 原文地址:https://www.cnblogs.com/dingkui/p/6268744.html
Copyright © 2011-2022 走看看