Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$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