Monday, June 15, 2015

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 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.
Lets automate these manual steps with PowerShell.

PowerShell Script to Move IIS Web Site to New Physical Location:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Import IIS Module
Import-Module WebAdministration

#Variables
$WebAppURL="http://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.



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...