1+ function Get-NexusRepositoryServiceInstall {
2+ <#
3+ . SYNOPSIS
4+ If found, returns the name of the Nexus service and the install and data directories it uses.
5+
6+ . DESCRIPTION
7+ Checks all current services for services that run "nexus.exe", then returns the program and data directories for one/each.
8+
9+ . PARAMETER AllResults
10+ To speed up execution, by default we check services until we find the first one running nexus.exe.
11+ If you have more than one instance installed, you can use this switch to check all services.
12+
13+ . EXAMPLE
14+ Get-NexusRepositoryInstallValues
15+ #>
16+ [CmdletBinding ()]
17+ param (
18+ # By default, we assume there is only one service. This searches for all installed services.
19+ [switch ]$AllResults
20+ )
21+ # If you have a lot of services, searching them all may take longer -
22+ # so we can stop searching when we find the first service matching nexus.exe.
23+ $ResultCount = @ {}
24+ if (-not $AllResults ) { $ResultCount.First = 1 }
25+
26+ $NexusService = Get-ChildItem HKLM:\System\CurrentControlSet\Services\ | Where-Object {
27+ ($ImagePath = Get-ItemProperty - Path $_.PSPath - Name ImagePath - ErrorAction SilentlyContinue) -and
28+ $ImagePath.ImagePath.Trim (' "'' ' ).EndsWith(' \nexus.exe' )
29+ } | Select-Object @ResultCount
30+
31+ foreach ($Service in $NexusService ) {
32+ $ServiceName = $Service.PSChildName
33+ $TargetFolder = (Get-ItemProperty - Path $Service.PSPath ).ImagePath.Trim(' "'' ' ) | Split-Path | Split-Path
34+ $DataFolder = Convert-Path (Join-Path $TargetFolder " $ ( (Get-Content $TargetFolder \bin\nexus.vmoptions) -match ' ^-Dkaraf.data=(?<RelativePath>.+)$' -replace ' ^-Dkaraf.data=' ) " )
35+ [PSCustomObject ]@ {
36+ ServiceName = $ServiceName
37+ ProgramFolder = $TargetFolder
38+ DataFolder = $DataFolder
39+ }
40+ }
41+ }
0 commit comments