$axconfigFile = '\\cesta\konfigurace.axc' $domainName = 'domena' #region Functions function axApplicationPath ([string]$aosComputerName, [string]$aosNumber) { try { $HKLM = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $aosComputerName) $registryAOS = $HKLM.OpenSubKey("System\\CurrentControlSet\\Services\\Dynamics Server\\5.0\\$aosNumber") $registryConfig = $registryAOS.OpenSubKey('Original (installed configuration)').OpenSubKey('SetupProperties') $applicationPath = $registryConfig.GetValue('AosApplicationPath') + '\Appl\' + $registryConfig.GetValue('ApplicationInstanceName') } catch { throw $errorMessage = 'Klíč vzdáleného registru se nepodařilo otevřít' } return $applicationPath } function splitAosIdent($aosFullName) { $aosName, $computerNameAndPort = $aosFullName.Split("@") $computerName, $port = $computerNameAndPort.Split(":") return $aosName, $computerName, $port } #endregion $aosName, $aosComputerName, $aosPort = splitAosIdent -aosFullName ((Select-String $axconfigFile -Pattern "aos2,Text").Line).SubString(14) #v axc máme názvy počítačů bez domény, ale při přístupu přes VPN potřebuji plně kvalikované jméno $aosComputerName += ".$domainName" $aosService = (Get-Service -DisplayName "Dynamics AX Object Server 5.0`$*$aosName" -ComputerName $aosComputerName) [string]$aosNumber = $aosService.Name.Substring(6) $appLocalPath = axApplicationPath -aosComputerName $aosComputerName -aosNumber $aosNumber if (!$appLocalPath) { throw 'Cesta k aplikačnímu adresáři nebyla nalezena' } #konverze lokální cesty na UNC if ($appLocalPath.StartsWith('\\')) { $appUncPath = $appLocalPath; } else { $appUncPath = join-path "\\$aosComputerName" $appLocalPath.Replace(':', '$') } New-Object PSObject -Property @{ AosComputerName = $aosComputerName AosName = $aosName AosPort = $aosPort AosNumber = $aosNumber AosServiceInstance = $aosService AppLocalPath = $appLocalPath AppUncPath = $appUncPath }