frameworkResources/Scripts/Resources_Scripts/virtual_machine.ps1
|
function Get-LinuxNCacheInstallDir { param( [Parameter(Mandatory = $true)] [string]$VMName, [Parameter(Mandatory = $true)] [string]$ResourceGroupName ) $Path = $null try { # 1. Fetch VM and check its tags $vm = Get-AzVM -Name $VMName -ResourceGroupName $ResourceGroupName -ErrorAction Stop if ($vm.Tags.ContainsKey("InstallNCacheDir") -and $vm.Tags["InstallNCacheDir"]) { $Path = $vm.Tags["InstallNCacheDir"] } else { Write-Host "No 'InstallNCacheDir' tag found on VM '$VMName'. Using default '/opt/ncache'." -ForegroundColor Yellow $Path = "/opt/ncache" } } catch { Write-Warning "Failed to fetch VM info for '$VMName'. Using default '/opt/ncache'. $_" $Path = "/opt/ncache" } # 2. Normalize slashes (Linux default) $Path = $Path -replace '\\', '/' # 3. Ensure path ends with 'ncache' if ($Path -notmatch "(?i)ncache$") { $Path = (Join-Path $Path "ncache") } return $Path } |