Skip to content

Instantly share code, notes, and snippets.

@torgro
Last active February 17, 2018 22:56
Show Gist options
  • Save torgro/9d5ac32f01be9e30ace90487c4c06cb1 to your computer and use it in GitHub Desktop.
Save torgro/9d5ac32f01be9e30ace90487c4c06cb1 to your computer and use it in GitHub Desktop.
function Get-FileApi
{
[cmdletbinding()]
Param(
[Parameter(Mandatory)]
[hashtable]
$Authorization
,
[string]
$Name
)
$invokeSplat = @{
Uri = "http://localhost:11000/api/file"
Method = "Get"
}
$headersSplat = @{
Headers = @{
Authorization = $Authorization.Authorization
}
}
if (-not [string]::IsNullOrEmpty($Name))
{
$headersSplat.Headers.Name = $Name
}
$files = Invoke-RestMethod @invokeSplat @headersSplat
if ($files.error)
{
throw $files.error.message
}
if ([string]::IsNullOrEmpty($Name))
{
$files
}
else
{
$files | Where-Object Name -like $Name
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment