function Initialize-GraylogServiceVault { try { $null = Get-SecretVault Graylog -ErrorAction Stop } catch { try { $null = Register-SecretVault "Graylog" -ModuleName "Microsoft.PowerShell.SecretStore" -ErrorAction Stop } catch { throw "Failed to create the Graylog secret vault: $_" } } try { $null = Get-Secret Graylog_BaseURI -Vault Graylog -ErrorAction Stop } catch { try { do { Write-Host "The Graylog Base URI secret is missing, prompting for input..." $local:Graylog_Host = [string](Read-Host -Prompt "Enter Graylog Host (e.g. graylog.example.com)") $local:Graylog_Port = [int](Read-Host -Prompt "Enter Graylog Port (e.g. 80, 443, 9000, etc)") $local:Graylog_IsHTTPS = [bool]$Host.UI.PromptForChoice("Graylog Base URI - Is the application served over HTTPS?", "(Is there a lock symbol when you visit the app?)", @("&No", "&Yes"), 0) $local:Graylog_Protocol = if ($local:Graylog_IsHTTPS) { "https" } else { "http" } $local:Graylog_BaseURI = "${local:Graylog_Protocol}://${local:Graylog_Host}:${local:Graylog_Port}" $local:Graylog_IsBaseURICorrect = [bool]$Host.UI.PromptForChoice("Graylog Base URI - Is the following URI correct?", $local:Graylog_BaseURI, @("&No", "&Yes"), 0) } while (-NOT $local:Graylog_IsBaseURICorrect) $null = $local:Graylog_BaseURI | Set-Secret Graylog_BaseURI -ErrorAction Stop } catch { throw "Failed to set the Graylog Base URI secret: $_" } } try { $null = Get-Secret Graylog_Credential -Vault Graylog -ErrorAction Stop } catch { try { Write-Host "The Graylog Credential secret is missing, prompting for input..." Get-Credential -Message "Enter your Graylog credentials (the same way as you would via the web service)" | Set-Secret Graylog_Credential -ErrorAction Stop } catch { throw "Failed to set the Graylog Credential secret: $_" } } }