-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAOS_RemoveMetadataSymbolicLinks.ps1
96 lines (76 loc) · 3.51 KB
/
AOS_RemoveMetadataSymbolicLinks.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
<#
.SYNOPSIS
Removes symbolic links for all the D365FO modules registered in Metadata folder from AOSService\PackagesLocalDirectory.
.DESCRIPTION
*** Script version: AOS_RemoveMetadataSymbolicLinks.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.
Existing AOS Modules are skipped.
*** NOTE: Please run the script as administrator
.EXAMPLE
PS> .\AOS_RemoveMetadataSymbolicLinks.ps1
Removes symbolic links from AOSService\PackagesLocalDirectory, the folder will be auto-found if it's in a root drive location (for example C:\AOSService\PackagesLocalDirectory).
.EXAMPLE
PS> .\AOS_RemoveMetadataSymbolicLinks.ps1 -PackagesLocalFolder "C:\CustomAOS\PackagesLocalDirectory"
Removes symbolic links from the specified folder.
#>
# Input parameters
param
(
[Parameter(Mandatory=$false,
HelpMessage = 'If specified this will be the folder from which symbolic links will be removed.')]
[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 Docentric 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 remove 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) {
(Get-Item "$AOSModulePath").Delete() | Out-Null
if($error.count -eq 0) {
Write-Host " Removed symbolic link for model '$ModelFolder': $AOSModulePath" -ForegroundColor Green
} else {
Write-Host " Failed to remove symbolic link for model '$ModelFolder': $AOSModulePath" -ForegroundColor Red
Write-Host " Error: $($error)" -ForegroundColor Red
$error.clear()
}
} else {
Write-Host " Model folder '$ModelFolder' is missing in AOS 'PackagesLocalDirectory' folder. Action is skipped." -ForegroundColor Yellow
}
}
Write-Host "`nScript completed."
Set-StrictMode -Off