jmohan0302
asked on
Looking for a script
Need a script to find whether IIS is installed for a list of servers. If IIS is installed I need a script to find what are all the websites are hosted? is it possible to get a script for this
Do you mean your own servers on your own network?
ASKER
yes
Hi, try this. Run it from a command prompt using
cscript ShowWebsites.vbs
Regards,
Rob.
cscript ShowWebsites.vbs
Regards,
Rob.
strServers = "servers.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objFile = objFSO.OpenTextFile(strServers, ForReading, False)
While Not objFile.AtEndOfStream
strServer = Trim(objFile.ReadLine)
If strServer <> "" Then
If Ping(strServer) = True Then
WScript.Echo vbCrLf & "Web Sites on " & strServer & ":"
strIISPath = "IIS://" & ServerName & "/W3SVC"
On Error Resume Next
Set objIIS = GetObject(strIISPath)
If Err.Number = 0 Then
For Each objItem In objIIS
If Item.Class = "IIsWebServer" Then
WScript.Echo Item.name
End If
Next
Else
WScript.Echo "Error retrieving list of sites from " & strServer
End If
Else
strServer & " is offline."
End If
End If
Wend
objFile.Close
WScript.Echo vbCrLf & "Finished."
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
ASKER
Hi Rob,
I am getting sysntax error when I ran this script. I tried this from my laptop. Do we need to run this only from a server
I am getting sysntax error when I ran this script. I tried this from my laptop. Do we need to run this only from a server
ASKER
My apologies, please change this line:
strServer & " is offline."
to this:
WScript.Echo strServer & " is offline."
You can run it from any domain computer, as long as the user account has admin rights on the target machines.
Regards,
Rob.
strServer & " is offline."
to this:
WScript.Echo strServer & " is offline."
You can run it from any domain computer, as long as the user account has admin rights on the target machines.
Regards,
Rob.
ASKER
Hi Rob,
Thanks a lot. I have corrected it . Thanks . Is there any script to find whether IIS service is installed or not from a list of servers?
Thanks a lot. I have corrected it . Thanks . Is there any script to find whether IIS service is installed or not from a list of servers?
OK, I've made the script check for the existence, and the status, of the IISAdmin service. Hopefully that's enough.
Regards,
Rob.
Regards,
Rob.
strServers = "servers.txt"
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objFile = objFSO.OpenTextFile(strServers, ForReading, False)
While Not objFile.AtEndOfStream
strServer = Trim(objFile.ReadLine)
If strServer <> "" Then
If Ping(strServer) = True Then
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name = 'iisadmin'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
blnInstalled = False
blnRunning = False
For Each objItem In colItems
blnInstalled = True
If objItem.Status = "Running" Then blnRunning = True
Next
WScript.Echo "IIS Installed: " & blnInstalled
WScript.Echo "IIS Running: " & blnRunning
If blnInstalled = True Then
WScript.Echo vbCrLf & "Web Sites on " & strServer & ":"
strIISPath = "IIS://" & ServerName & "/W3SVC"
On Error Resume Next
Set objIIS = GetObject(strIISPath)
If Err.Number = 0 Then
For Each objItem In objIIS
If Item.Class = "IIsWebServer" Then
WScript.Echo Item.name
End If
Next
Else
WScript.Echo "Error retrieving list of sites from " & strServer
End If
End If
Else
WScript.Echo strServer & " is offline."
End If
End If
Wend
objFile.Close
WScript.Echo vbCrLf & "Finished."
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
ASKER
Hi Rob,
Thanks a lot. The scripts are working fine. When I ran the script it says only one site is running. It is not giving the iis instances names. Actually I am looking for the list of websites or URLs configured under Default Website for a list of servers where IIS is configured. Could you please help me in getting the script for my requirement? Really thanks a lot.
Thanks a lot. The scripts are working fine. When I ran the script it says only one site is running. It is not giving the iis instances names. Actually I am looking for the list of websites or URLs configured under Default Website for a list of servers where IIS is configured. Could you please help me in getting the script for my requirement? Really thanks a lot.
ASKER
Hi, I haven't tested this too much, but see what this gives you. I'll work some more on it tomorrow.
Rob.
Rob.
strServers = "servers.txt"
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objFile = objFSO.OpenTextFile(strServers, ForReading, False)
While Not objFile.AtEndOfStream
strServer = Trim(objFile.ReadLine)
If strServer <> "" Then
If Ping(strServer) = True Then
WScript.Echo "Checking " & strServer
Set objWMIService = GetObject("winmgmts:\\" & strServer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name = 'iisadmin'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
blnInstalled = False
blnRunning = False
For Each objItem In colItems
blnInstalled = True
If objItem.State = "Running" Then blnRunning = True
Next
WScript.Echo "IIS Installed: " & blnInstalled
WScript.Echo "IIS Running: " & blnRunning
If blnInstalled = True Then
WScript.Echo vbCrLf & "Web Sites on " & strServer & ":"
strIISPath = UCase("IIS://" & strServer & "/W3SVC")
On Error Resume Next
Err.Clear
WScript.Echo "Connecting to " & strIISPath
Set objIIS = GetObject(strIISPath)
If Err.Number = 0 Then
For Each objItem In objIIS
If objItem.Class = "IIsWebServer" Then
WScript.Echo "Site ID: " & objItem.name
WScript.Echo "Server Comment: " & objItem.ServerComment
End If
Next
Else
WScript.Echo "Error retrieving list of sites from " & strServer & ". Error " & Err.Number & ": " & Err.Description
End If
On Error GoTo 0
End If
Else
WScript.Echo strServer & " is offline."
End If
End If
Wend
objFile.Close
WScript.Echo vbCrLf & "Finished."
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
ASKER
Hi Rob,
The script is running fine. I really appreciate the efforts you have shown to me so far. Thanks a lot. The script says whether IIS is running or not. So one part of my query is resolved. The other part I am looking is that what are all the URLs configured on that server.I mean that what are the websites configured on a server. I kindly request you to give me a script which displays the configured websites on a server. Thanks
Please find the screen shot of the above script:
The script is running fine. I really appreciate the efforts you have shown to me so far. Thanks a lot. The script says whether IIS is running or not. So one part of my query is resolved. The other part I am looking is that what are all the URLs configured on that server.I mean that what are the websites configured on a server. I kindly request you to give me a script which displays the configured websites on a server. Thanks
Please find the screen shot of the above script:
Hi, does this give you the correct web site names?
Rob.
Rob.
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "YourWebServer"
WScript.Echo "Computer: " & strComputer
Set objLocator= CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = objLocator.ConnectServer(strComputer, "root/MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM IIsWebVirtualDir", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
Set nodeObj = objWMIService.Get("IIsWebVirtualDirSetting='" & objItem.Name & "'")
WScript.Echo nodeObj.AppFriendlyName
Next
ASKER
Hi Rob,
Yes its working fine. Is it possible to combine both the scripts. I mean if we combine both the script, I will get my output. That is the script has to find for a list of servers whether IIS server is running or not. If running it has to give the list of websites configured. My objective is to find out of the entire inventory I have to find what are all the server that are configured with IIS service and what are all the sites configured. Thanks
Yes its working fine. Is it possible to combine both the scripts. I mean if we combine both the script, I will get my output. That is the script has to find for a list of servers whether IIS server is running or not. If running it has to give the list of websites configured. My objective is to find out of the entire inventory I have to find what are all the server that are configured with IIS service and what are all the sites configured. Thanks
Sure, I was just making sure that snippet was going to give you the results before I combined them.
Try this. I have combined the snippets.
Regards,
Rob.
Try this. I have combined the snippets.
Regards,
Rob.
strServers = "servers.txt"
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objLocator= CreateObject("WbemScripting.SWbemLocator")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Set objFile = objFSO.OpenTextFile(strServers, ForReading, False)
While Not objFile.AtEndOfStream
strServer = Trim(objFile.ReadLine)
If strServer <> "" Then
If Ping(strServer) = True Then
WScript.Echo "Checking " & strServer
On Error Resume Next
Set objWMIService = objLocator.ConnectServer(strServer, "root/MicrosoftIISv2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Service WHERE Name = 'iisadmin'", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
If Err.Number = 0 Then
blnInstalled = False
blnRunning = False
For Each objItem In colItems
blnInstalled = True
If objItem.State = "Running" Then blnRunning = True
Next
WScript.Echo "IIS Installed: " & blnInstalled
WScript.Echo "IIS Running: " & blnRunning
If blnInstalled = True Then
WScript.Echo vbCrLf & "Web Sites on " & strServer & ":"
On Error Resume Next
Set colItems = objWMIService.ExecQuery("SELECT * FROM IIsWebVirtualDir", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
Set nodeObj = objWMIService.Get("IIsWebVirtualDirSetting='" & objItem.Name & "'")
WScript.Echo nodeObj.AppFriendlyName
Next
WScript.Echo VbCrLf
Err.Clear
On Error GoTo 0
End If
Else
WScript.Echo "Error connecting to the IIS provider on " & strServer & ". Error " & Err.Number & ": " & Err.Description
Err.Clear
On Error GoTo 0
End If
Else
WScript.Echo strServer & " is offline."
End If
End If
Wend
objFile.Close
WScript.Echo vbCrLf & "Finished."
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
ASKER
Try changing this:
Set objWMIService = objLocator.ConnectServer(s trServer, "root/MicrosoftIISv2")
to this
Set objWMIService = objLocator.ConnectServer(s trServer, "root/MicrosoftIISv2", strServer & "\Administrator", "LocalAdminPassword")
so that you connect using credentials local to each remote computer. Hopefully your local admin password is the same across the servers, so it will work against them all.
Regards,
Rob.
Set objWMIService = objLocator.ConnectServer(s
to this
Set objWMIService = objLocator.ConnectServer(s
so that you connect using credentials local to each remote computer. Hopefully your local admin password is the same across the servers, so it will work against them all.
Regards,
Rob.
ASKER
Hi Rob,
I am using domain account. so how can I pass my domain credentials into the script. Thanks
I am using domain account. so how can I pass my domain credentials into the script. Thanks
I'll have to check the WMI Security on the MicrosoftIISv2 namespace when I get back to work tomorrow, but I have a feeling the default security will be limited to local accounts only, since I already tried it with domain credentials and it didn't appear to work.
I'll get back to you.
Regards,
Rob.
I'll get back to you.
Regards,
Rob.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
good