-
-
Save jtn-webkoncept/b0f29c61f0e916cba8a254652c45b1e9 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
$pp = ( | |
"wp-rocket/wp-rocket.php" | |
) | |
$cosandsec = "consumer_key=ck_5939183e8b8&consumer_secret=cs_8f710d1b8056" | |
$c1 = 0 | |
$m = Get-Content -Path $csvnosort | Measure-Object -line | |
@($m).lines | |
$myOutput = @() # Declare empty array | |
#get csv data | |
$csvnosort = "C:\Users\Dern\Desktop\PS2020\MainWP\website-scan-de-re-act\input\input.csv" | |
$csv = Import-Csv C:\Users\Dern\Desktop\PS2020\MainWP\website-scan-de-re-act\input\input.csv -Header @("id","domainurl") | |
#for each line in the csv file do this: | |
$myOutput += foreach ($data in $csv) { | |
$c1++ | |
Write-Progress -Id 0 -Activity 'Running plugin updates' -Status "Processing $($c1) of $(@($m).lines)" -CurrentOperation "$data" -PercentComplete (($c1 / @($m).lines) * 100) | |
# Combine processing: | |
try { | |
Write-Host "Now Processing:" $data.id | |
#deactivate plugin | |
$Urldeactivate = "https://wk-kontrol.dk/wp-json/mainwp/v1/site/site-manage-plugin?site_id=$($data.id)&plugin=$($pp)&action=deactivate&$($cosandsec)" | |
$deactivateplugin = Invoke-RestMethod -Headers @{"Cache-Control"="no-cache"} -Method 'Post' -Uri $Urldeactivate | |
$deactivateplugin.flag | |
Write-host "Deactivation complete" | |
#lookforvalue | |
$invoker = Invoke-RestMethod -Headers @{"Cache-Control"="no-cache"} $data.domainurl | |
$cutcontent = $invoker.Contains("https://kit.fontawesome.com/44ac.js") | |
Write-host "Search complete" | |
#reactivate plugin | |
$Urlactivate = "https://adminsite.ok/wp-json/mainwp/v1/site/site-manage-plugin?site_id=$($data.id)&plugin=$($pp)&action=activate&$($cosandsec)" | |
$reactivateplugin = Invoke-RestMethod -Headers @{"Cache-Control"="no-cache"} -Method 'Post' -Uri $Urlactivate | |
$reactivateplugin.flag | |
Write-host "activation complete" | |
[PSCustomObject]@{ | |
websiteid = $data.id | |
pluginpath = $pp | |
deactivation = $deactivateplugin.success | |
activation = $reactivateplugin.success | |
StatusdescriptionValue = '200' | |
Statusdescription = 'SUCCESS' | |
# findstr | |
DomainName = $data.domainurl | |
iscodepresent = $cutcontent | |
} | |
} | |
catch { | |
# catcherrors | |
[PSCustomObject]@{ | |
websiteid = $data.id | |
pluginpath = $pp | |
Exceptionmessage = $_.Exception.Message | |
StatusdescriptionValue = $_.Exception.Response.StatusCode.value__ | |
Statusdescription = $_.Exception.Response.StatusDescription | |
deactivation = $deactivateplugin.success | |
activation = $reactivateplugin.success | |
# findstr | |
DomainName = $data.domainurl | |
iscodepresent = $cutcontent | |
} | |
} | |
} | |
$myOutput | Select-Object -Property websiteid, DomainName, | |
pluginpath, | |
deactivation, | |
iscodepresent, | |
activation, | |
Exceptionmessage, | |
Exceptionresponse, | |
StatusdescriptionValue, | |
Statusdescription, | |
error| | |
Export-Csv -NoTypeInformation -Path C:\Users\Dern\Desktop\PS2020\MainWP\website-scan-de-re-act\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