Skip to content

Instantly share code, notes, and snippets.

@torgro
Last active February 17, 2018 23:36
Show Gist options
  • Save torgro/c157f0e4c4c75b4cee1f6d6d441b5e2e to your computer and use it in GitHub Desktop.
Save torgro/c157f0e4c4c75b4cee1f6d6d441b5e2e to your computer and use it in GitHub Desktop.
function Set-FileApi
{
[cmdletbinding(
SupportsShouldProcess
)]
Param(
[Parameter(Mandatory)]
[hashtable]
$Authorization
,
[string]
$FileName
,
[string]
$Content = [string]::Empty
)
$invokeSplat = @{
Uri = "http://localhost:11000/api/file"
Method = "Post"
}
$body = @{
Authorization = $Authorization.Authorization
FileName = $FileName
Content = $Content
}
if ($PSCmdlet.ShouldProcess($FileName, "Set content"))
{
$respons = Invoke-RestMethod @invokeSplat -Body $body
if ($respons.error)
{
throw $respons.error.message
}
else
{
$respons
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment