Move SharePoint Web Application’s IIS Physical Path to a New Location

Requirement: Move SharePoint web application’s IIS physical location from system drive (c:\) to application drive (d:\) due to new server support policies!

Solution:

SharePoint web applications, by default placed under: “C:\inetpub\wwwroot\wss\VirtualDirectories” when we create them. There is no UI/direct way to change the physical location of SharePoint IIS web sites later. However, these three steps can be utilized to move the SharePoint web application’s IIS physical directory to a new location:

  1. Copy all contents from the current virtual directory to new directory
  2. Change IIS website’s physical path
  3. Update SharePoint web application to point to the new directory path.

Let’s automate these manual steps with PowerShell.

PowerShell Script to Move IIS Website to New Physical Location:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Import IIS Module
Import-Module WebAdministration

#Variables
$WebAppURL="https://intranet.crescent.com/"
$NewPath="D:\IIS\VirtualDirectories\Intranet.Crescent.com"     
$IISSiteName = "Crescent Intranet" 
 
#Get Web Applications' IIS Settings
$WebApp = Get-SPWebApplication $WebAppURL
$IISSettings = $WebApp.IisSettings[[Microsoft.SharePoint.Administration.SPUrlZone]::Default]
$OldPath = $IISSettings.Path

#Check if destination folder exists already. If not, create the folder
if (!(Test-Path -path $NewPath))        
{            
    $DestFolder = New-Item $NewPath -type directory          
}

#***** Step 1 - Copy Current Virutal Directory to new location **** #
Copy-Item -Path $OldPath\* -Destination $NewPath -Force -Recurse 

#***** Step 2 - Change IIS Web Site's Physical path ******
Set-ItemProperty "IIS:\Sites\$($IISSiteName)" -name PhysicalPath -value $NewPath

#***** Step 3 - Update SharePoint Web Application ******
#Change the Web App path
$IISSettings.Path = $NewPath
#Update Web Application
$WebApp.Update()

Please note, You’ll have to repeat steps 1 and 2 in all SharePoint web front-end servers.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

One thought on “Move SharePoint Web Application’s IIS Physical Path to a New Location

  • An absolute life saver when moving Central Admin off the system drive. Works like a champ.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *