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

1

6

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...

Bumpy answered 27/11, 2019 at 23:37 Comment(3)
The new cmdlets should be easier to use learn.microsoft.com/en-us/iis/get-started/whats-new-in-iis-10/…Angular
But still not able to see the physicalPath PS C:\> $Site = Get-IISSite "Default Web Site" PS C:\> $Site.Attributes Where could it be?Bumpy
That's because the physical path is a property under virtual directory, learn.microsoft.com/en-us/iis/get-started/… Open applicationHost.config and you should soon learn it.Angular
E
13

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.

Eb answered 28/11, 2019 at 3:9 Comment(1)
Thanks, I spend almost an hour searching for it.Astringent

© 2022 - 2024 — McMap. All rights reserved.