File upload to the Master Action Site in powershell

Hello All,

I’d like to upload a file to the master action site and have ‘Send to clients’ checked through a script. I can do this successfully using cUrl as follows:

curl -k -H “Authorization: Basic xxxxxxxxxxxxxxxxx==” -H “ISClientFile: 1” -X POST -F “file=TEST_FILE.txt” “https://core_server:52311/api/site/master/files”

I would like to do the same in Powershell. I am able to upload with no problem, but I can’t seem to get ‘Send to clients’ checked.

this is a simplified version of my script:

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", 'Basic #########################==')
$headers.Add("ISClientFile", '1')

#Ignore SSL Warning
add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

$FilePath = "TEST_FILE.txt"
$uploadResult = Invoke-RestMethod -Uri https://core_server:52311/api/site/master/file/TEST_FILE.txt -Headers $headers -Method POST -InFile $FilePath -ContentType 'multipart/form-data' -ErrorAction SilentlyContinue -ErrorVariable uploadError -OutVariable uploadResult

Any guidance would be greatly appreciated

I would not recommend doing this unless it is a small file that doesn’t change very often.

I’m not sure why this wouldn’t work in powershell. I don’t see anything obvious.

Thanks for looking at it.

Can you elaborate on why you would recommend against this. I’ve been using this method to distribute a building to subnet lookup table since our initial installation without any issues