Functions/Get-GraylogSidecarConfigFile.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 |
<#
.SYNOPSIS Get the current sidecar configuration. .DESCRIPTION Read the configuration file sidecar.yml and parse the relevant values ServerUrl, ServerApiToken and NodeName. It will return a custom object with the three properties. .EXAMPLE PS C:\> Get-GraylogSidecarConfigFile Get the current sidecar configuration. #> function Get-GraylogSidecarConfigFile { [CmdletBinding()] [OutputType([System.String])] param () $path = 'C:\Program Files\Graylog\sidecar\sidecar.yml' $result = [PSCustomObject] @{ ServerUrl = '' ServerApiToken = '' NodeName = '' } # Extract the configuration values $config = Get-Content -Path $path -Raw -ErrorAction 'SilentlyContinue' if ($config -match 'server_url: "(?<ServerUrl>.*)"') { $result.ServerUrl = $Matches.ServerUrl } if ($config -match 'server_api_token: "(?<ServerApiToken>.*)"') { $result.ServerApiToken = $Matches.ServerApiToken } if ($config -match 'node_name: "(?<NodeName>.*)"') { $result.NodeName = $Matches.NodeName } Write-Output $result } |