How to update "physical path" of a site on IIS 10 using Powershell?

9.3k Views Asked by At

When creating a site I manage to set the path with the following line of code

New-WebSite -Name "mysite" -port 8084 -PhysicalPath "c:\inetpub\wwwroot" -ApplicationPool "myappPool"

I have tried to figure out how to update the path, nothing found via Configuration Editor. I thought I had it with the following command

Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST'  -filter "system.applicationHost/sites/site[@name='mysite']/virtualDirectoryDefaults" -name "physicalPath" -value "c:\inetpub\wwwroot\mysite"

...but, it is not virtualdirectory I want to update, but the actual site...

1

There are 1 best solutions below

1
Jalpa Panchal On BEST ANSWER

You could use below PowerShell command to change the iis site physical path.

run PowerShell as administrator.

run below command:

PS C:\WINDOWS\system32> Import-Module WebAdministration
PS C:\WINDOWS\system32>  Set-ItemProperty IIS:\Sites\sitea -name physicalPath -value "D:\s1"

after changing the path open iis manager and refresh the site.