Private/Invoke-DTXAPI.ps1
Function Invoke-DTXAPI{ param ( # Parameter help description [Parameter()] [String] $DTXUsername = $script:DTXUsername, # Parameter help description [Parameter()] [String] $DTXPassword = $script:DTXPassword, # Parameter help description [Parameter()] [String] $RootURI = "https://dtx-capgemini.rhysevans.co.uk", # Parameter help description [Parameter()] [String] $URI = "/project", # Parameter help description [Parameter()] [String] $Payload, # Parameter help description [Parameter()] [String] $Method = "Get", # Parameter help description [Parameter()] [String] $ContentType = "application/json" ) if(-not $script:DTXUsername){ throw "NO DTX USERNAME. Use Set-DTXCredential -Username user -Password pass" } if(-not $script:DTXPassword){ throw "NO DTX PASSWORD. Use Set-DTXCredential -Username user -Password pass" } if($URI[0] -ne "/"){ $URI = "/" + $URI } $Splat = @{ Credential = (New-Object System.Management.Automation.PSCredential ($DTXUsername, (ConvertTo-SecureString $DTXPassword -AsPlainText -Force))) Uri = ($RootURI + $URI) ContentType = $ContentType Method = $Method } if($PSVersionTable.OS){ $Splat.Authentication = "Basic" } if($Payload){ $Splat.Body = $Payload } Invoke-RestMethod @Splat } |