Write-HTElasticDocument.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
46
function Write-HTElasticDocument {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$true)]
        [string]$ElasticUri,

        [Parameter(Mandatory=$true)]
        [string]$Index,

        [Parameter(Mandatory=$true)]
        [string]$Type,

        [Parameter(Mandatory=$true)]
        [string]$Document,

        [Parameter(Mandatory=$true)]
        [string]$ElasticUser,

        [Parameter(Mandatory=$true)]
        [string]$ElasticUserp
        
    )

    process {
        $es_username = $ElasticUser
        $es_password = $ElasticUserp
        $es_uri =  "$ElasticUri/$Index/$Type"

        $es_securecred = ConvertTo-SecureString $es_password -AsPlainText -Force

        $es_creds = New-Object -TypeName 'System.Management.Automation.PSCredential' -ArgumentList $es_username, $es_securecred


        $param = @{
            'Uri' = $es_uri;
            'Method' = 'POST';
            'Credential' = $es_creds;
            'Body' = $Document
            }

        $Result = Invoke-WebRequest @param

        Write-Output $Result.Content

    }
}