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