Public/Save-ConnectorFile.ps1
|
<# .SYNOPSIS Internal use only. Not intended for public use. #> function Save-ConnectorFile { [CmdletBinding()] param ( [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [ValidateNotNullOrEmpty()] [ValidatePattern("\.zip$")] [string] $Path ) process { if (-not $Script:APIRoot -or -not $Script:AccessTokenProfile) { throw "Connector not connected. Please run Connect-Connector first." } Write-Verbose "Downloading ZIP file '$Path' from connector data download endpoint" Invoke-RestMethod ` -Uri "$($Script:APIRoot)data/download" ` -Method Get ` -OutFile $Path ` -Headers (Get-EntraIDAccessTokenHeader -Profile $Script:AccessTokenProfile) ` -SkipHttpErrorCheck ` -StatusCodeVariable statuscode if($statuscode -ge 200 -and $statuscode -lt 300) { Write-Verbose "File download successful with status code $statuscode" } else { Write-Warning "File download failed with status code $statuscode" } } } |