• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 322
  • Last Modified:

Changing the Site ID on IIS

Hello,

Could anyone tell me how to change the siteID on IIS?

Thanks!!
0
jackrocks
Asked:
jackrocks
  • 5
  • 3
1 Solution
 
Chris DentPowerShell DeveloperCommented:

You can't change it, you can potentially copy the settings from one ID to another. However it depends on the version of IIS. Not sure IIS 6 will like you playing with it (autogenerated there).

Anyway, it's the Site Indentifier is a container object for all the site settings in the IIS Metabase.

But then... the interesting question is why would you want to? ;)
0
 
jackrocksAuthor Commented:
We have a cluster of 5 machines on which the site ID's on 3 machines is 12 but on the other two its 11. I want to have site ID's to be the same on all the machines. We have IIS 5.0. What do you suggest the possible solution to be??

Thanks
Jack
0
 
Chris DentPowerShell DeveloperCommented:

It's possible if you script the creation of the site - that would allow you to connect / create to a specific SiteID to contain all the site objects.

Copying all the settings between isn't a really huge problem - but also either scripted or manual work.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
jackrocksAuthor Commented:
Chris,

I dunno how to copy the settings of IIS from one site to another. Could you please let me know how to do this? Any link that has the steps involved will be helpful to me a lot.Thanks!
0
 
Chris DentPowerShell DeveloperCommented:

Yeah, I have some scripts to do a lot of it... give me a little time to put them into a reasonable state.
0
 
Chris DentPowerShell DeveloperCommented:

Okay... this script (VBScript) is rather long, and not necessarily comprehensive. The new site cannot be started until you delete the old one. I haven't written that kind of functionality in because it's not very helpful if the newly created site doesn't have a complete set of information.

' Script to copy a Web Server from one Site ID to another
' Compatible with IIS 4 and IIS 5

Option Explicit

' Global Constants

Const SOURCE_ID = <ID its on at the moment>
Const TARGET_ID = <ID You Want the Site on>
Const SERVER_NAME = "<Your Server>"

' Variable Declaration

Dim objService, objSourceServer, objSourceVDir, objTargetServer, objTargetVDir, objUser
Dim strServerComment, strLogFileDir, strLogFlags, strAccessFlags, strAuthFlags
Dim strAnonUser, strAnonPass, strSitePath
Dim arrBindings, arrHTTPErrors

'
' Functions
'

Function GeneratePassword()

      ' This function generates a random password consisting of up to 4 upper case characters
      ' and lower case characters and up to 3 numbers.
      '
      ' If Password Length is altered the restrictions on the characters must also be changed.

      Dim intUCharCount, intLCharCount, intNumCount, intPassLen, intRNumber
      Dim strChar, strPass

      Const PASSWORD_LENGTH = 10
      
      intUCharCount = 0
      intLCharCount = 0
      intNumCount = 0
      intPassLen = 0
      
      Do while intPassLen < PASSWORD_LENGTH
        Randomize()
            intRNumber = Int(123 * Rnd() + 1)
            If (intRNumber > 64) and (intRNumber < 91) Then
                  If (intUCharCount <= 3) Then
                        strChar = Chr(intRNumber)
                        strPass = strPass & strChar
                        intUCharCount = intUCharCount + 1
                        intPassLen = intPassLen + 1
                  End If
            End If
            If (intRNumber > 96) and (intRNumber < 123) Then
                  If (intLCharCount <= 3) Then
                        strChar = Chr(intRNumber)
                        strPass = strPass & strChar
                        intLCharCount = intLCharCount + 1
                        intPassLen = intPassLen + 1
                  End If
            End If
            If (intNumCount <= 2) Then
                  Randomize()
                  intRNumber = Int(9 * Rnd() + 1)
                  strChar = CStr(intRNumber)
                  strPass = strPass & strChar
                  intNumCount = intNumCount + 1
                  intPassLen = intPassLen + 1
            End If
      Loop
      GeneratePassword = strPass
End Function

'
' Main Code
'

' Connection to the Web Service

Set objService = GetObject("IIS://" & SERVER_NAME & "/W3SVC")

' Global Constants

' Connect to the old site and read in details

Set objSourceServer = GetObject("IIS://" & SERVER_NAME & "/W3SVC/" & SOURCE_ID)
Set objSourceVDir = GetObject("IIS://" & SERVER_NAME & "/W3SVC/" & SOURCE_ID & "/ROOT")

' General and Log Properties

strServerComment = objSourceServer.ServerComment
arrBindings = objSourceServer.ServerBindings
strLogFileDir = objSourceServer.LogFileDirectory
strLogFlags = objSourceServer.LogExtFileFlags

' Access and Auth Properties

strAccessFlags = objSourceServer.AccessFlags
strAuthFlags = objSourceServer.AuthFlags

' Reading the Anonymous Password isn't reliable so isn't set.

strAnonUser = objSourceServer.AnonymousUserName

' Custom Errors

arrHTTPErrors = objSourceServer.HTTPErrors

' Read the Path for the Site

strSitePath = objSourceVDir.Path

' Create Web Server on the Target ID

Set objTargetServer = objService.Create("IIsWebServer", TARGET_ID)
Set objTargetVDir = objTargetServer.Create("IIsWebVirtualDir", "ROOT")

' General and Log Properties

objTargetServer.ServerComment = strServerComment
objTargetServer.ServerBindings = arrBindings
objTargetServer.LogFileDirectory = strLogFileDir
objTargetServer.LogExtFileFlags = strLogFlags

' Access and Auth Properties

objTargetServer.AccessFlags = strAccessFlags
objTargetServer.AuthFlags = strAuthFlags

objTargetServer.AnonymousUserName = strAnonUser

' This setting disables the ability of IIS to manage the anonymous user password

objTargetServer.AnonymousPasswordSync = False

' If you want to set the Anonymous Password automatically you can use this
' Just remove the comment character from the next few of lines
' It assumes the Anonymous User is a local user on the system

' strAnonPass = GeneratePassword()

' Connect to Account Management and reset password

' Err.Clear
' On Error Resume Next
' Set objUser = GetObject("WinNT://" & SERVER_NAME & "/" & strAnonUser & ",user")
' If (Err <> 0) Then
'       wscript.echo "Could not connect to " & strAnonUser
' Else
'       objUser.SetPassword strAnonPass
'       objUser.SetInfo
'       wscript.echo "Reset Password for " & strAnonUser & ": " & strAnonUser
' End If
' Err.Clear

' objTargetServer.AnonymousUserPassword = strAnonPass

' Custom Errors

objTargetServer.HTTPErrors = arrHTTPErrors

' Set the Path for the Site

objTargetVDir.Path = strSitePath

' Write the Properties to the new site

objTargetServer.SetInfo
objTargetVDir.SetInfo
0
 
jackrocksAuthor Commented:
Thanks a lot..its working!!! I have one more question. Can I use the same SSL certificate with the newly created site?

Thanks
Jack
0
 
Chris DentPowerShell DeveloperCommented:

Hi Jack,

Glad the script is working, there are more attributes that can be defined than I have above, if it's missing any just yell.

The certificate is slightly more difficult - each server would have to have a seperate certificate. It's a little hard to replicate those across servers.

Chris
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now