Skip to content

socketlabs/socketlabs-powershell

Repository files navigation

socketlabs-powershell

SocketLabs
Twitter Follow MIT licensed PRs Welcome GitHub contributors

The SocketLabs PowerShell module allows you to interact with our platform API using PowerShell.

Table of Contents

Prerequisites and Installation

Prerequisites

  • A supported .NET version
    • PowerShell 5.1 or PowerShell Core 6.1.0 or higher.
    • .NET version 4.6.1 or higher
    • .NET Standard 2.0 or higher
  • A SocketLabs account. If you don't have one yet, you can sign up for a free account to get started.

Installation

For most uses we recommend installing the SocketLabs PowerShell Module via the PowerShell Gallery. You can install the latest version of the module with the following command:

PS> Install-Module -Name SocketLabs -Force

Alternately, you can simply clone this repository directly to include the source code in your project.

Getting Started

Currently we only support the Injection API. This let's you send messages via HTTP injection using PowerShell

Injection API

Obtaining your API Key and SocketLabs ServerId number

In order to get started, you'll need to enable the Injection API feature in the SocketLabs Control Panel. Once logged in, navigate to your SocketLabs server's dashboard (if you only have one server on your account you'll be taken here immediately after logging in). Make note of your 4 or 5 digit ServerId number, as you'll need this along with your API key in order to use the Injection API.

To enable the Injection API, click on the "For Developers" dropdown on the top-level navigation, then choose the "Configure HTTP Injection API" option. Once here, you can enable the feature by choosing the "Enabled" option in the dropdown. Enabling the feature will also generate your API key, which you'll need (along with your ServerId) to start using the API. Be sure to click the "Update" button to save your changes once you are finished.

Managing API Keys

For ease of demonstration, many of our examples include the ServerId and API key directly in our code sample. Generally it is not considered a good practice to store sensitive information like this directly in your code.

We recommend storing your API Key and ServerId as environment variables.

PS C:\> $target = [System.EnvironmentVariableTarget]::User
PS C:\> $apiKey = "XXXXX123456ABCDE"
PS C:\> $serverId = "1000"
PS C:\> [System.Environment]::SetEnvironmentVariable("SL_API_KEY", $apiKey, $target)
PS C:\> [System.Environment]::SetEnvironmentVariable("SL_SERVER_ID", $serverId, $target)

Usage

Examples

Output a list of processess to an email recipient.

PS C:\> Get-Process | Out-SocketLabs -Sender "sysadm@example.com" -Recipients "infra@example.com", "logs@example.com" -Subject "Here is the list of running processes."

Get IP Address information from the current host

PS C:\> $request = Invoke-WebRequest -Uri "https://ifconfig.co/json" -UseBasicParsing
PS C:\> $request.Content | ConvertFrom-Json | Format-Table ip, country*, hostname | 
>> Out-SocketLabs -Sender "sysadm@example.com" `
>> -Recipients "infra@example.com", "logs@example.com" `
>> -Subject "Here is the list of running processes."

License

The SocketLabs PowerShell module and all associated code, including any code samples, are MIT Licensed.

About

SocketLabs Email Delivery PowerShell Client Module https://www.socketlabs.com

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •