Hi guys,
I'm trying to create a script that will take a csv file, and upload it to my FreePBX server to create/edit an extension. Here's what I have so far. I seem to be getting past the login page and into the Bulk Extensions page, but I can't figure out how to actually send the file. I'm very new to Invoke-WebRequest, so even tips on how to debug would be great.
# PowerShell Invoke-WebRequest Example
$URLBulkExtensions = "server/…/config.php
$loginParams = @{username='admin';password='pass'}
# Log into FreePBX
Write-Host -NoNewline "Logging into FreePBX… "
$Request = Invoke-WebRequest -Uri $URLBulkExtensions -Method POST -building $loginParams -SessionVariable WebSession
if ($Request.StatusCode -eq 200) {
Write-Host -ForegroundColor Green "OK"
}
Start-Sleep 2
$Request.Forms[0].Fields.csv_type = 'input'
$Request.Forms[0].Fields.csvFile = 'bulkext_test.csv'
Invoke-WebRequest -Uri $URLBulkExtensions -Method POST -building $Request.Forms[0].Fields -WebSession $WebSession -ContentType "multipart/form-data"