-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAOS_CreateMetadataSymbolicLinks.ps1
93 lines (73 loc) · 3.25 KB
/
AOS_CreateMetadataSymbolicLinks.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
<#
.SYNOPSIS
Creates symbolic links for all the D365FO modules registered in Metadata folder to AOSService\PackagesLocalDirectory.
.DESCRIPTION
*** Script version: AOS_CreateMetadataSymbolicLinks.ps1 v1.1 ***
When using source control repositories such as GIT you have only one source location.
D365FO requires separate location for Modules (Metadata) and Projects connecting the source files
together in a structured and organized way. The script creates symbolic links for all
the D365FO modules registered in Metadata folder to AOSService\PackagesLocalDirectory.
Existing AOS Modules are skipped.
*** NOTE: Please run the script as administrator
.PARAMETER PackagesLocalFolder
Specify a custom AOS PackagesLocalDirectory path.
.EXAMPLE
PS> .\AOS_CreateMetadataSymbolicLinks.ps1
Creates symbolic links for all models.
.EXAMPLE
PS> .\AOS_CreateMetadataSymbolicLinks.ps1 -PackagesLocalFolder "C:\CustomAOS\PackagesLocalDirectory"
Creates symbolic links for all models.
#>
# Input parameters
param
(
[Parameter(Mandatory=$false,
HelpMessage = 'If specified this will be the folder in which symbolic links are to be created.')]
[String]$PackagesLocalFolder
)
#Requires -RunAsAdministrator
## https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-strictmode
Set-StrictMode -Version 3.0
## Searching for AOS folder
$AOSMetadataPath = ""
if ([System.String]::IsNullOrWhiteSpace($PackagesLocalFolder))
{
Get-Partition | Where-Object { $AOSMetadataPath -eq "" } | ForEach-Object {
if(Test-Path ($_.DriveLetter+":\AOSService\PackagesLocalDirectory")) {
$AOSMetadataPath = ($_.DriveLetter+":\AOSService\PackagesLocalDirectory")
}
}
} else {
$AOSMetadataPath = $PackagesLocalFolder
}
## If path is missing exit the script
if(!$AOSMetadataPath)
{
Write-Host "The AOS PackagesLocalDirectory folder is missing (e.g., C:\AOSService\PackagesLocalDirectory)." -ForegroundColor Red
Exit
}
## Register all the repository Metadata folders (Modules) as Symbolic links to AOS
$RepoMetadataPath = ".\Metadata"
if(!(Test-Path $RepoMetadataPath)) {
Write-Host "The 'Metadata' folder containing all D365FO modules is missing. Please check if script was run from the same folder as the script is located in." -ForegroundColor Red
Exit
}
Write-Host "AOS PackagesLocal Folder: $AOSMetadataPath"
Write-Host "GIT Metadata Folder: $RepoMetadataPath"
Write-Host "`nStarting to register AOS metadata symbolic links...`n"
$RepoModelFolders = Get-ChildItem $RepoMetadataPath -Directory
foreach ($ModelFolder in $RepoModelFolders)
{
$Target = "$RepoMetadataPath\$ModelFolder"
## The full destination path
$AOSModulePath = [System.IO.Path]::Combine($AOSMetadataPath, $ModelFolder)
if (!(Test-Path $AOSModulePath))
{
New-Item -ItemType SymbolicLink -Path "$AOSMetadataPath" -Name "$ModelFolder" -Value "$Target" -ErrorAction Stop | Out-Null
Write-Host " Created symbolic link for model '$ModelFolder': $AOSModulePath" -ForegroundColor Green
} else {
Write-Host " Model folder '$ModelFolder' already exists in AOS 'PackagesLocalDirectory' folder. Action is skipped." -ForegroundColor Yellow
}
}
Write-Host "`nScript completed."
Set-StrictMode -Off