Last Updated: February 25, 2016
·
914
· joshuadoshua

Download Latest WP in PowerShell

One of the things I really love about WordPress is the speed of development. This is a PowerShell function to download the latest version of WordPress and unzip it into a given directory inside wamp/www

function newWp
{
    param([string] $name)

    Set-Location C:\wamp\www\

    ## download latest version of wp

    $file = "http://wordpress.org/latest.zip"
    $wp = "c:\wamp\www\wordpress.zip"

    $wc = New-Object System.Net.WebClient
    $wc.DownloadFile($file,$wp)

    ## unzip wp file

    $shellApp = New-Object -com shell.application
    $zip = $shellApp.NameSpace($wp)
    $dir = $shellApp.NameSpace((Get-Location).Path)

    foreach($item  in $zip.items()){        
        $shellApp.NameSpace($dir).CopyHere($item)
    }

    ## clean up | rename dir and remove zip

    Rename-Item C:\wamp\www\wordpress $name
    Remove-Item .\wordpress.zip

    Write-Host "WordPress Copied into " $name
}

Copy this into your PowerShell profile, set your appropriate pathes, restart PowerShell and run ~/newWp test

To really streamline development, it's not hard to create a function to copy your own sandbox theme into the new install

I'm no PowerShell expert, comments/suggestions welcome!

ESTHER HARWANTI has a good read on how to setup a PowerShell Profile @
http://hadget.blogspot.com/2012/12/how-to-create-powershell-profile.html