最新消息:ww12345678 的部落格重装上线,希望大家继续支持。

AX 2012 – Export models in Sequence

网络文摘 William 1237浏览 0评论

Using powershell to import Ax model is a very straight forward approach.

I come under the situation where i have to export more than 1 model and need to let others know what sequence they go in because of their dependencies.

For this I maintain an excel sheet which the models / ID’s

So that means a few things while exporting:

1. They need to be in sequence

2. File naming conventions (Because we all have our own)

3. Painstaking process when we have to type the file name, model for each model we export.

Solution steps:

1. Powershell

2. Profits!

Ok explaining the solution, here is my powershell script which takes in the ModelId’s as a CSV string (no spaces) (so -ModelIds 32,33,45)

The database and server (database server) are defaulted (which can still be changed). Even the folder where this goes has a parameter.

It reads the modelIds that need to be exported (in the same sequence) and create file names with the suffix so that they are numbered.

You might say that if there are more than 9 models to be exported, then i need to do something with it (I havent reached that stage yet), but here is the script to share:

Param(
	#[Parameter(Mandatory=$true)]
	[String]
	$AxDBServerSource = 'SQLSERV_2012_1',
    [String]
	#[Parameter(Mandatory=$true)]
	$AxDBSource = 'ax_2012_r2_cu6_model',
#	[String]$AxDBServerDest = '.',
#	[String]
#	[Parameter(Mandatory=$true)]
#	$AxDBDest = 'AX_Standard_2012_new',
	#[Parameter(Mandatory=$true)]
	[String]$FolderTempModelStore = 'E:tempshashimodels'
	,[Parameter(Mandatory=$true)]
	[int[]]$ModelIds
)
#Created By: Shashi Sadasivan

function deleteLocalCache {
	Write-host 'Deleting *.AUC files'
    $localAppDataDir = "$(gc env:LOCALAPPDATA)"
	del $localAppDataDir*.auc
}

CLS #Clears the screen
#Load the Ax Powershell script
Write-Host 'Loading Ax powershell scripts....'
& "E:Program FilesMicrosoft Dynamics AX60ManagementUtilitiesMicrosoft.Dynamics.ManagementUtilities.ps1"

#Printing the Details of values (Not necessary)
Write-Host 'Host Database: ' $AxDBServerSource''$AxDBSource
#Write-Host 'Destination Database: ' $AxDBServerDest''$AxDBDest
Write-Host 'Temporary folder:' $FolderTempModelStore

deleteLocalCache

#Export Models from source
#Delete Contents of Folder first
Write-Host 'Deleting Contents of Folder.....'
Get-ChildItem -Path $FolderTempModelStore -Recurse | Remove-Item -Force -Recurse
Write-Host 'Exporting Models to Folder......'

$AxModelListSource = Get-AXModel -Server $AxDBServerSource -Database $AxDBSource
$sequence = 0
foreach($modelId in $ModelIds)
{
	$sequence++
	$modelSource = $AxModelListSource | Where-Object {$_.ModelId -eq $modelId}
	if($modelSource -eq $null) {
		Write-Host "Model id" $modelId "not found in the application" -foregroundcolor "Red"
	}
	else {
		#Write-Host "Export Model " $modelSource.Name
		$locFileName = "$FolderTempModelStore$($sequence)_$($modelSource.Layer)_$($modelSource.Name)_$($modelSource.Version).axmodel"
		#Write-Host $locFileName
		#Write-Host 'Exporting Model' $modelSource.Name
		Export-AXModel -Server $AxDBServerSource -Database $AxDBSource -Model $modelSource.ModelId -File $locFileName
	}
}

Filed under: Ax 2012, Dynamics Ax Tagged: ax 2012, Dynamics Ax, powershell

转载请注明:ww12345678 的部落格 | AX Helper » AX 2012 – Export models in Sequence

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址