The Temple of Fu

code, systems and games

Move IIS Data Directory script

leave a comment »

I can’t remember how I got this script or from where but I have used it twice now so I am posting it here for others. If you are the original script author please let me know and i would be glad to tag it as such!

'------------------------------------------------------- '
' FILE: moveIISDataDirectory.vbs
' Used to migrate Web Data (FTP, WWW, SMTP) from drive C:\INETPUB to drive D:\INETPUB.
' This script can be modified to meet the need of any customers.
' Please do not remove this header info though.
'--------------------------------------------------------

'Stop IIS services before continuing

Set WSHShell = Wscript.CreateObject("Wscript.Shell")
WSHShell.PopUp "Stopping all Internet Services..."
ret = WshShell.Run ("net stop iisadmin /y", 1, TRUE)

If ret = 0 then
WSHShell.PopUp "IISADMIN service was stopped successfully, continuing"
'restart()
else
WSHShell.PopUp "IISADMIN failed to stop successfully. The error code is " & ret Wscript.Quit 1
end if

' Modify IIS Metabase Properties for new data location
Dim params(7)
Dim x, ret
Dim params2(3) Params(0) = "w3svc/1/root/path d:\inetpub\wwwroot"
Params(1) = "w3svc/1/root/scripts/path d:\inetpub\scripts "
Params(2) = "w3svc/1/root/iissamples/path d:\inetpub\iissamples"
Params(3) = "msftpsvc/1/root/path d:\inetpub\ftproot"
Params(4) = "smtpsvc/1/BadMailDirectory d:\inetpub\mailroot\BadMail"
Params(5) = "smtpsvc/1/PickupDirectory d:\inetpub\mailroot\Pickup"
Params(6) = "smtpsvc/1/QueueDirectory d:\inetpub\mailroot\Queue"
Params(7) = "smtpsvc/1/DropDirectory d:\inetpub\mailroot\Drop"

Set WshSysEnv = WshShell.Environment("PROCESS")

For Each x In Params
ret = WSHShell.Run ("cscript.exe " & "c:\inetpub\adminscripts\adsutil.vbs SET " & x, 1, TRUE)
Next

' Verify Settings were successfully applied
If ret = 0 then
WSHShell.PopUp "The new metabase settings have been successfully updated. The new Web Data path is D:\inetpub"
else
WSHShell.PopUp "The Configuration changes failed. The error code is " & ret Wscript.Quit 1
end if

wscript.Sleep 5000

' Move Data to new location (D:\inetpub) using xcopy.exe (this can be changed from xcopy to move so the data is actually moved from current locale)
ret = WSHShell.Run ("xcopy c:\inetpub d:\inetpub\ /s /e /q" , 1, TRUE)

If ret = 0 then
WSHShell.PopUp "The data has been successfully moved to d:\inetpub"
else
WSHShell.PopUp "The data move failed. The error code is " & ret Wscript.Quit 1
end if

' Update Web Catalog to be for d:\inetpub 'Stop Content Index Service
Set WSHShell = Wscript.CreateObject("Wscript.Shell")
WSHShell.PopUp "Stopping Index Service..."
ret = WshShell.Run ("net stop cisvc", 1, TRUE)

If ret = 0 then
chgeCat()
else
WSHShell.PopUp "Content Index service failed to stop successfully. The error code is " & ret Wscript.Quit 1
end if

Function chgeCat()
Set WshShell = WScript.CreateObject("WScript.Shell")

'Delete Catalogs '
WshShell.RegDelete "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ContentIndex\Catalogs\Web\"

' Delete Web Catalog. '
WshShell.RegDelete "HKLM\SYSTEM\CurrentControlSet\Control\ContentIndex\Catalogs\System\"

' Delete System Catalog. 'Modify existing Web catalog entry
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ContentIndex\Catalogs\Web\Location", "d:\inetpub"
WshShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ContentIndex\Catalogs\Web\IsIndexingW3Svc", 1, "REG_DWORD"
end function

'Start Services (WWW, FTP, SMTP, CISVC)
Set WSHShell = Wscript.CreateObject("Wscript.Shell")
WSHShell.PopUp "Attempting to restart stopped Services..."
Params2(0) = "w3svc"
Params2(1) = "msftpsvc"
Params2(2) = "cisvc"
Params2(3) = "smtpsvc"

For Each x In Params2
ret = WshShell.Run ("net start " & x, 1, TRUE)
wscript.Sleep 5000
Next

If ret = 0 then
WSHShell.PopUp "Services were started successfully, modifications complete"
else
WSHShell.PopUp "One or more services fail to start successfully. The error code is " & ret Wscript.Quit 1
end if

Advertisements

Written by lordfu

March 25, 2010 at 3:54 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: