2024-07-25 02:31:34 +01:00
|
|
|
function ConvertFrom-GraylogSession {
|
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Converts a WebRequestSession object to a JSON string.
|
|
|
|
.DESCRIPTION
|
|
|
|
Converts a WebRequestSession object to a JSON string.
|
|
|
|
.PARAMETER InputObject
|
|
|
|
The WebRequestSession object to convert to a JSON string.
|
|
|
|
.OUTPUTS
|
|
|
|
A JSON string containing the properties of the WebRequestSession object.
|
|
|
|
.EXAMPLE
|
|
|
|
ConvertFrom-Session -WebSession $global:GraylogSession
|
|
|
|
Converts the WebRequestSession object to a JSON string.
|
|
|
|
.EXAMPLE
|
|
|
|
$global:GraylogSession | ConvertFrom-Session
|
|
|
|
Converts the WebRequestSession object to a JSON string.
|
|
|
|
#>
|
|
|
|
param (
|
|
|
|
[Parameter(Mandatory, ValueFromPipeline)]
|
|
|
|
[Microsoft.PowerShell.Commands.WebRequestSession]
|
|
|
|
$InputObject
|
|
|
|
)
|
|
|
|
|
2024-07-25 02:45:49 +01:00
|
|
|
try { $local:Graylog_BaseURI = Get-Secret Graylog_BaseURI -Vault Graylog -AsPlainText }
|
2024-07-25 02:31:34 +01:00
|
|
|
catch { Initialize-ServiceVault }
|
|
|
|
# $Output = @{
|
|
|
|
# Headers = $InputObject.Headers
|
|
|
|
# Cookies = [Collections.Generic.List[PSCustomObject]]::new()
|
|
|
|
# UseDefaultCredentials = $InputObject.UseDefaultCredentials
|
|
|
|
# Credentials = $InputObject.Credentials
|
|
|
|
# Certificates = $InputObject.Certificates
|
|
|
|
# UserAgent = $InputObject.UserAgent
|
|
|
|
# Proxy = $InputObject.Proxy
|
|
|
|
# MaximumRedirection = $InputObject.MaximumRedirection
|
|
|
|
# MaximumRetryCount = $InputObject.MaximumRetryCount
|
|
|
|
# RetryIntervalInSeconds = $InputObject.RetryIntervalInSeconds
|
|
|
|
# }
|
2024-07-26 13:54:54 +01:00
|
|
|
$Output = $InputObject | Select-Object -ExcludeProperty Cookies
|
|
|
|
$Output | Add-Member -MemberType NoteProperty -Name Cookies -Value ([Collections.Generic.List[PSCustomObject]]@())
|
2024-07-25 02:31:34 +01:00
|
|
|
if ($InputObject.Cookies.Count) {
|
|
|
|
# GetAllCookies is only available in PowerShell Core :c
|
|
|
|
$InputObject.Cookies.GetCookies($local:Graylog_BaseURI) | ForEach-Object {
|
|
|
|
$Output.Cookies.Add(
|
|
|
|
[PSCustomObject]@{
|
|
|
|
Name = $_.Name
|
|
|
|
Value = $_.Value
|
|
|
|
Domain = $_.Domain
|
|
|
|
Path = $_.Path
|
|
|
|
Expires = $_.Expires
|
|
|
|
Secure = $_.Secure
|
|
|
|
HttpOnly = $_.HttpOnly
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ConvertTo-Json $Output
|
|
|
|
}
|