Last active
May 31, 2019 17:56
-
-
Save pmcfernandes/b31f5da6e6c3dd3930b0eca030d7894e to your computer and use it in GitHub Desktop.
Update all instances of wordpress in a parent folder
This file contains hidden or 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
# Tool to update wordpress website in Windows | |
# Author: Pedro Fernandes | |
# update-wp.ps1 | |
param([String]$spaces = "E:\HostingSpaces") | |
Write-Host "update-wp.ps1- Tool update wordpress website in Windows" | |
Write-Host "Usage:" | |
Write-Host " -spaces: Location of WebSites in local system" | |
Write-Host "" | |
Write-Host "" | |
$wp = "latest.zip" | |
$temp = "$spaces\_temp_" | |
$output = "$spaces\$wp" | |
# Create folder if not exists | |
New-Item -ItemType Directory -Force -Path $temp | Out-Null | |
$start_time = Get-Date | |
Invoke-WebRequest -Uri "https://wordpress.org/$wp" -OutFile $output | Out-Null | |
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)" | |
Add-Type -AssemblyName System.IO.Compression.FileSystem | |
[System.IO.Compression.ZipFile]::ExtractToDirectory($output, $temp) | |
Get-ChildItem -Path "$temp\wordpress" -Recurse | Move-Item -Destination $temp | |
Remove-Item "$temp\wordpress" -Recurse | |
Remove-Item "$output" | |
ForEach ($d in Get-ChildItem -Path $spaces -Recurse -Include wp-config.php) | |
{ | |
$destinationPath = $d.Directory.FullName | |
Write-Host $destinationPath | |
Copy-Item -Path "$temp\*" -Destination $destinationPath -Recurse -Force | |
} | |
Remove-Item $temp -Recurse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment