Public/CloudFactory/Invoke-CFApi.ps1
function Invoke-CFApi { [CmdletBinding()] param ( [Parameter(Mandatory)] [string]$Uri, [Parameter()] [Microsoft.PowerShell.Commands.WebRequestMethod] $Method = 'Get', [Parameter()] $Body ) try { # Get access token $token = Get-CFAccessToken $baseURI = "https://portal.api.cloudfactory.dk/" $params = @{ Uri = $baseURI + $Uri Method = $Method Headers = @{ Authorization = 'Bearer ' + $token.AccessToken accept = 'application/json, text/plain, */*' } ContentType = 'application/json' } if ($Body) { $params.Body = ($Body | ConvertTo-Json -Depth 100) } $response = Invoke-RestMethod @params return $response } catch { throw } } |