How to upload files to Skatteverkets navet e-transport with powershell

skatteverketWhen you want to collateral an identity against the Swedish tax agency Skatteverkets service Navet one part of the process is to upload a bulk file to their service “E-transport”. In Skatteverkets technical documentation they recommend freeware program curl in windows environments, but they refer to the developer for support. The upload can easily be done with powershell and invoke-webrequest.

$produktidentitet = "xxxxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxxx"
$infil = "C:\temp\datafil.txt"

#get certificate
$certificate = Get-ChildItem -Path cert:\CurrentUser\My | where dnsnamelist -Like "*skatte*"

#Upload to Skatteverket
Invoke-WebRequest -Uri "$produktidentitet" -CertificateThumbprint $certificate.Thumbprint -Method Post -InFile $infil