PSGraylog/Functions/ConvertFrom-GraylogSession.ps1

56 lines
1.8 KiB
PowerShell
Raw Normal View History

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
)
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
# }
$Output = $InputObject
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
}