'****************************************************
'		Script Witten by Larry Heintz
'		April 2006 www.windowsadminscripts.com
' This script will enumerate all Mime Types on a
' computer. You can also search for Mime types by
' Content Type.
'
' Script Usage:
' List All Mime Types:
'  cscript enumMimes.vbs /computer:[computername] /list
' Search for a Mime Content Type:
'  cscript enumMimes.vbs /computer:[computername] /search:[search text]
'****************************************************
Dim args,computername,list,search
Set args = Wscript.Arguments.Named
computername = args.Item("computer")
list = args.Item("list")
search = args.Item("search")

if computername = "" then
	computername = getComputer()
else
	computername = computername
end if

if wscript.arguments.count = 0 then
	wscript.echo "Script Usage:"
	wscript.echo "List All Mime Types:"
	wscript.echo " cscript enumMimes.vbs /computer:[computername] /list"
	wscript.echo "Search for a Mime Content Type:"
	wscript.echo " cscript enumMimes.vbs /computer:[computername] /search:[search text]"
	wscript.quit
elseif args.exists("list") then
	Call enumMimes(computername)
elseif args.exists("search") then
	if search = "" then
		wscript.echo "The script has ended due to no Search Text given"
		wscript.quit
	else
		search = trim(lcase(search))
	end if
	Call searchMimes(computername,search)
else
	wscript.echo "Script Usage:"
	wscript.echo "List All Mime Types:"
	wscript.echo " cscript enumMimes.vbs /computer:[computername] /list"
	wscript.echo "Search for a Mime Content Type:"
	wscript.echo " cscript enumMimes.vbs /computer:[computername] /search:[search text]"
	wscript.quit
end if

Function enumMimes(computer)
On Error Resume Next
Dim objMime,MimeMapping,count
count = 0
Set objMime = GetObject("IIS://" & computer & "/MimeMap")
if not (errorChecking (computer)) then
	wscript.echo "Registered File Types on " & ucase(computer)
	wscript.echo "====================================" & VbCrLF
	For Each MimeMapping in objMime.MimeMap
		count = count + 1
		wscript.echo "Extension: " & MimeMapping.Extension & " Content Type: " & MimeMapping.MimeType
	Next
	if count <> 0 then
		wscript.echo VbCrLF & "There are " & count & " different Mime Types on " & ucase(computer)
	else
		wscript.echo "I am sorry there no Mime Types  on " & ucase(computer)
	end if	
end if
Set objMime = nothing
End Function

Function searchMimes(computer,ctype)
On Error Resume Next
Dim objMime,MimeMapping,temp,count
count = 0
Set objMime = GetObject("IIS://" & computer & "/MimeMap")
if not (errorChecking (computer)) then
	wscript.echo ctype & " Mime Content Type on " & ucase(computer)
	wscript.echo "============================================" & VbCrLF
	For Each MimeMapping in objMime.MimeMap
		temp = split(MimeMapping.MimeType,"/")
		if instr(temp(0),ctype) <> 0 then
		count = count + 1
			wscript.echo "Extension: " & MimeMapping.Extension & " Content Type: " & MimeMapping.MimeType
		end if
	Next
	if count <> 0 then
		wscript.echo VbCrLF & "There are " & count & " different Mime Extensions matching the Content Type you have searched for"
	else
		wscript.echo "I am sorry there no Mime Extensions matching the Content Type you have searched for"
	end if
end if
Set objMime = nothing
End Function

Function getComputer()
	Dim objNet
	Set objNet = WScript.CreateObject("WScript.Network") 
	getComputer = objNet.ComputerName 
	Set objNet = Nothing 
End Function

Function errorChecking(computername) 
errorChecking = False 
if err.number <> 0 then 
	wscript.echo "Unable to connect to " & ucase(computername)
	err.Clear () 
	errorChecking = True
	wscript.quit
end if 
end Function
