-
-
Save jtn-webkoncept/c7efb31b07474e6af7f2b525ec42db97 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$pluginpath = "forminator/forminator.php" | |
$cosandsec = "consumer_key=ck_5daadfa8&consumer_secret=cs_8adfa97b10d1b8056" | |
$FileList = (Get-ChildItem 'C:\Users\Dern\Desktop\PS2020\MainWP\PUT-Pluginupdate\updatelist\updateme.txt').fullname | |
$c1 = 0 | |
$lineamount = | |
$m = Get-Content -Path $FileList | Measure-Object -line | |
@($m).lines | |
$myOutput = @() # Declare empty array | |
foreach ($listedid in $FileList) { | |
$myOutput += foreach ($websiteid in (Get-Content $listedid)) { | |
$c1++ | |
Write-Host "Processing $websiteid" | |
Write-Progress -Id 0 -Activity 'Running plugin updates' -Status "Processing $($c1) of $(@($m).lines)" -CurrentOperation $websiteid -PercentComplete (($c1 / @($m).lines) * 100) | |
try { | |
try { | |
$Url = "https://test.dk/wp-json/mainwp/v1/site/site-update-item?site_id=$($websiteid)&type=plugin&slug=$($pluginpath)&$($cosandsec)" | |
$updateprocess = Invoke-RestMethod -Method 'Put' -Uri $url | |
write-host "dette er url $url" | |
# create custom objects and run API call | |
[PSCustomObject]@{ | |
websiteid = $websiteid | |
Exceptionmessage = $_.Exception.Message | |
Exceptionresponse = $_.Exception.Response | |
StatusdescriptionValue = $_.Exception.Response.StatusCode.value__ | |
Statusdescription = $_.Exception.Response.StatusDescription | |
} | |
} catch { | |
# catcherrors | |
[PSCustomObject]@{ | |
websiteid = $websiteid | |
Exceptionmessage = $_.Exception.Message | |
Exceptionresponse = $_.Exception.Response | |
StatusdescriptionValue = $_.Exception.Response.StatusCode.value__ | |
Statusdescription = $_.Exception.Response.StatusDescription | |
} | |
} | |
} catch { | |
# catcherrorsouter | |
[PSCustomObject]@{ | |
websiteid = $websiteid | |
Exceptionmessage = $_.Exception.Message | |
Exceptionresponse = $_.Exception.Response | |
StatusdescriptionValue = $_.Exception.Response.StatusCode.value__ | |
Statusdescription = $_.Exception.Response.StatusDescription | |
} | |
} | |
} | |
} | |
$myOutput | Select-Object -Property websiteid, | |
Exceptionmessage, | |
Exceptionresponse, | |
StatusdescriptionValue, | |
Statusdescription | | |
Export-Csv -NoTypeInformation -Path C:\Users\Dern\Desktop\PS2020\MainWP\PUT-Pluginupdate\Output\output.csv | |
# or | |
$myOutput | Out-GridView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment