Skip to content

Instantly share code, notes, and snippets.

@torgro torgro/Get-FileApi.ps1
Last active Feb 17, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.