NN.KeySMS.psm1
#Region '.\Private\Get-KsAccessToken.ps1' 0 function Get-KsAccessToken { param ( [string]$accessTokenPath = "$env:USERPROFILE\.creds\KeySMS\keySmsAccessToken.xml" ) if (!(Test-Path $accessTokenPath)) { New-KsAccessToken } Import-Clixml $accessTokenPath | ConvertFrom-SecureString -AsPlainText } #EndRegion '.\Private\Get-KsAccessToken.ps1' 11 #Region '.\Public\New-KsAccessToken.ps1' 0 function New-KsAccessToken { param ( [string]$accessTokenPath = "$env:USERPROFILE\.creds\KeySMS\keySmsAccessToken.xml" ) $apiKey = Read-Host "Enter API key" -AsSecureString #Create parent folders of the access token file $accessTokenDir = $accessTokenPath.Substring(0, $accessTokenPath.lastIndexOf('\')) if (!(Test-Path $accessTokenDir)) { New-Item -ItemType Directory $accessTokenDir | Out-Null } #Create access token file $apiKey | Export-Clixml $accessTokenPath } #EndRegion '.\Public\New-KsAccessToken.ps1' 16 #Region '.\Public\Send-KsSms.ps1' 0 function Send-KsSms { param ( [Parameter(Mandatory)][string]$senderName, [Parameter(Mandatory)][string]$username, [Parameter(Mandatory)][array]$receivers, [Parameter(Mandatory)][string]$message ) $splat = @{ "Method" = "GET" "Uri" = "https://api.keysms.no/v1/messages/send" "Body" = @{ "apiKey" = Get-KsAccessToken "message" = $message "sender" = $senderName "username" = $username "receivers" = $receivers -join "," } } Invoke-RestMethod @splat } #EndRegion '.\Public\Send-KsSms.ps1' 21 |