New Functionality - Parameter for IIS folder(s)

Jan 17, 2012 at 7:51 PM

Hello,

the script take by default the the default systeme location for the inetpub. In my case I have to take in backup the IIS folder located on the C drive but Also the D: drive. Maybe adding in the parameter xml file this option could be a good idea?

Btw you did a fantastik job on this scipt!

Coordinator
Jan 18, 2012 at 8:25 PM
Edited Jan 19, 2012 at 2:38 PM

Hi,

First many thanks for your feedback. I respond to the IIS issue you. mention above.  I have written another method to backup the IIS virtual directories.

As you will be aware, when creating a web application, one of the fields allows you to set the path to the virtual directory. The default path is ususally IIS root: <Drive:>\inetpub\wwwroot\wss\VirtualDirectories\80 (Normally C:\ unless you have moved IIS from default to another drive which is a manual process)  

I have changed the code to collect the path to the virtual directories and then backup the virtual directory and/or the web.config.

I think you will find this a much better approach and much more flexible/robust. The new method will be available in the next release, probably from tomorrow midday.

Darren

Coordinator
Jan 20, 2012 at 7:45 AM

Hi, I have moved the responses to your issue regarding IIS here for the benefit of all.

Firstly, the script is written to backup SharePoint related IIS elements only. So Metadata (IIS Config which includes the ApplicationHost.config), Virtual Directories of the respective Zones for each Web Application and the Web.Config again for each Zone of each Web Application. The script is not written to back up every Virtual Directory in IIS.

If you run the following:

#Start Code

#Region Get IIS Web Root (IIS Web Root = <Drive>:\inetpub\wwwroot\wss\VirtualDirectories)

function Get-IISWebRoot

{            

               # Determine location of IIS (Note: IIS may have been installed to non default path, hence we check to determine correct path.)

               $key = "HKLM:\SOFTWARE\Microsoft\InetStp" 

               $value = "PathWWWRoot"

               $PathWWWRoot = Get-RegistryValue $key $value

               return $PathWWWRoot

}

#EndRegion

 #Region Read value(s) from registry key

function Get-RegistryValue

{  

               try {

                                   (Get-ItemProperty $key $value -ErrorAction Stop).$value

               }

               catch

               {

                                   $errText = $error[0].Exception.Message

                                   Write-Host "Error: Error reading registry. $errText"

               }

}            

#EndRegion

 Get-IISWebRoot # Call Get-IISWebRoot

#End Code

 What does it return? You should get something like this: C:\inetpub\wwwroot if you have not moved IIS to a non-default path.

 IMPORTANT: THE VALUE RETURNED IS THE DEFAULT PATH OF YOUR IIS AND NOT NECESSARILY THE PATH TO WHICH YOUR SHAREPOINT VIRTUAL DIRECTORIES ARE INSTALLED TO.

To move your IIS to a non default path you would need to carry out something like this: http://sharepointingitout.blogspot.com/2008/12/iis-70-move-inetpub-to-non-system-drive.html

 This is exactly why I changed the code, because of the fact that the path to the virtual directories can be changed when creating the web application. So here for example:

 $iisSettings = $webApplication.iisSettings[$Zone] # Get the IIS settings for the zone

$IISPath = $iisSettings.Path.ToString() # Get path from IIS settings

 The above two lines are an extract from the code in the script. This is how I determine the path to the respective virtual directories. The code will iterate through each Web Application and each zone and backup each virtual directory.

So for example: If you've extended the web application and which results in additional site being created and the zone you select is INTRANET both Virtual directories and web.config for DEFAULT and INTRANET are backed up.

So as I say the path to the respective virtual directory is obtained using the lines of code above.

This script is NOT designed to backup NON SharePoint virtual directories, so it won't backup your default site in IIS for example, it will only backup those virtual directories relating to SharePoint.

Hope that makes it a little clearer.

Coordinator
Jan 20, 2012 at 7:46 AM
Edited Jan 20, 2012 at 1:10 PM

OK....

Please run the following and post back your results. Also can you mail me your logfile from the script.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Region Get paths to SharePoint Virtual Directories
function Get-IISVirtualDirectories 
{
	
	try 
	{
		
		$spFarm = Get-SPFarm -ErrorAction Stop
		
		$urls = $spfarm.AlternateUrlCollections
			
		foreach ($url in $urls) 
		{  
			
			$webApplication = Get-SPWebApplication -Identity $url.IncomingUrl 
			$webApplicationName = $webApplication.DisplayName 	
			$Zone = $url.UrlZone # Get the default zone for the web application
			
			$iisSettings = $webApplication.iisSettings[$Zone] # Get the IIS settings for the zone

			$IISPath = $iisSettings.Path.ToString()  # Get path from IIS settings
		
			# Path to the  the SharePoint virtual directory
			Write-Host "SharePoint Virtual Directory for [$Zone] zone: [$IISPath]"
		}
	}
	catch
	{
		$errText = $error[0].Exception.Message
		Write-Host "Error obtaining Path to virtual directories. $errText"
	}
}
#EndRegion

#Start Code
#Region Get IIS Web Root (IIS Web Root = <Drive>:\inetpub\wwwroot)
function Get-IISWebRoot 
{	
	# Determine location of IIS (Note: IIS may have been installed to non default path, hence we check to determine correct path.)
	$key = "HKLM:\SOFTWARE\Microsoft\InetStp" 
	$value = "PathWWWRoot"
	$PathWWWRoot = Get-RegistryValue $key $value
	Write-Host "IIS WebRoot (Default Path): [$PathWWWRoot]"
}
#EndRegion

#Region Read value(s) from registry key
function Get-RegistryValue 
{    
	try 
	{
		(Get-ItemProperty $key $value -ErrorAction Stop).$value
	}
	catch
	{
		$errText = $error[0].Exception.Message
		Write-Host "Error reading registry. $errText"
	}
}	
#EndRegion

Get-IISWebRoot  # Call Get-IISWebRoot
Get-IISVirtualDirectories

#End Code

Jan 20, 2012 at 1:24 PM

Hi,

I ran the code above and I found that when it is not the Default zone returned by the line $Zone = $url.UrlZone.

the script return an error because the $iisSettings is null and the next line crash.

Maybe there is something i should change in my config?

Coordinator
Jan 20, 2012 at 1:37 PM

Hello,

Please run this and post back your results:

# Load the SharePoint snap-in for PowerShell

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Region Get Alternate Access Mappings
function Get-AccessMappings
{    	
	Get-SPFarm -ErrorAction Stop | Out-Null
	
	$AccessMappings = $spFarm.AlternateUrlCollections | Select Zone, InComingUrl, PublicUrl
	
	foreach ($AccessMapping in $AccessMappings){
	
		$Zone = $AccessMapping.Zone
		$InComingUrl = $AccessMapping.InComingUrl
		$PublicUrl = $AccessMapping.PublicUrl
		
		Write-Host "Incoming URL:" $InComingUrl "Zone:" $Zone "Public URL:" $PublicUrl
	}
}
#EndRegion



#Region 


	Get-AccessMappings

#EndRegion
Jan 20, 2012 at 3:51 PM

ok, Now I'm able to get zipped all my Sharepoint iis folder. but I got the 1kb zipped file issue on the 14Hive. the file 14Hive-20012012112625.zip is present but contains nothing

Coordinator
Jan 20, 2012 at 5:52 PM

I do not think you will have needed to make changes to the script but if you have can you share these changes.

For the 1KB issue can you start another discussion topic.  THANKS

Jan 23, 2012 at 3:05 PM

 

 In fact I just force using the Default Zone instead of detecting it because there was not match between the zones and the virtual directories except for the default ones.

function Backup-IISVirtualDirectories 
{
	
	Write-Log "Info: Backing up & compressing SharePoint virtual directories."
	
	try 
	{
		$urls = $spfarm.AlternateUrlCollections
			
		foreach ($url in $urls) 
		{  
			
			$webApplication = Get-SPWebApplication -Identity $url.IncomingUrl 
			$webApplicationName = $webApplication.DisplayName 	
			#$Zone = $url.UrlZone # Get the default zone for the web application
			$Zone = [microsoft.sharepoint.administration.spurlzone]::default 


.......
Coordinator
Jan 23, 2012 at 3:56 PM

Ok, I suspect this won't be a problem many people will encounter as I use the SharePoint API to return the Zones, and its the right way to do it, so for the time being I will leave it as it is but Thanks for your feedback.

Darren