-
-
Save jtn-webkoncept/cbff3c178d37ca0fbc40a2b974c4961a 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
$Ps7Times = [System.Collections.Generic.List[int]]::new() | |
$cosandsec = "consumer_key=ck_5939583e8b8&consumer_secret=cs_8f7452d671397b10d1b8056" | |
$FileList = (Get-ChildItem 'C:\Users\Dern\Desktop\PS2020\MainWP\UpdateWP\input\input-wp.txt').fullname | |
$c1 = 0 | |
$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-Progress -Id 0 -Activity 'Wordpress Update' -Status "Processing $($c1) of $(@($m).lines)" -CurrentOperation $websiteid -PercentComplete (($c1 / @($m).lines) * 100) | |
try { | |
$Stopwatch = [System.Diagnostics.Stopwatch]::new() | |
$Stopwatch.Start() | |
# Start parralel | |
$Targets = $websiteid | |
$Targets | ForEach-Object -ThrottleLimit 5 -Parallel { | |
$Url = "https://test.dk/wp-json/mainwp/v1/site/site-update-wordpress?site_id=$($websiteid)&$($cosandsec)" | |
$updateprocess = Invoke-RestMethod -Method 'Put' -Uri $url | |
Write-Host "Processing $websiteid " | |
write-Host "------------" | |
[PSCustomObject]@{ | |
websiteid = $websiteid | |
Exceptionmessage = $updateProcess.success | |
StatusdescriptionValue = '200' | |
Statusdescription = 'SUCCESS' | |
} | |
} # end parallel | |
$Stopwatch.Stop() | |
$Ps7Times.Add($Stopwatch.ElapsedMilliseconds) | |
} catch { | |
# catcherrors | |
[PSCustomObject]@{ | |
websiteid = $websiteid | |
Exceptionmessage = $_.Exception.Message | |
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\UpdateWP\output\output-wpu.csv | |
# or | |
$myOutput | Out-GridView | |
$Ps7Times | Measure -Average -Minimum -Maximum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment