Changing the physical path of an IIS website on a remote machine via Powershell

Ryan French picture Ryan French · Oct 15, 2010 · Viewed 25.9k times · Source

I'm currently working on a deployment script that will take my site, export it from svn, remove any testing files etc in it, minify the javascript/css, copy the code to a remote web server, and then switch the physical path of the existing site to the new directory.

So far I have everything working except for switching the physical directory in IIS.

$IIsServer = Get-WmiObject Site -Namespace "root/WebAdministration" -ComputerName $serverIP -Credential $credentials -Authentication PacketPrivacy
$site = $IIsServer | Where-Object {$_.Name -eq $siteName}

When I look into the values I have I cant find the physical path property.

Any suggestions would be greatly appreciated.

Answer

Doug picture Doug · Oct 15, 2012

This also works:

PS IIS:\Sites> Set-ItemProperty IIS:\Sites\Staging `
                   -name physicalPath `
                   -value "C:\blah\Web"

(Note the use of backticks for line continuations)