Currently I am able to to set a mime type with adsutil.vbs for the primary web site on IIS6 with the following syntax:
cscript adsutil.vbs set W3SVC/1/Root/MimeMap ".manifest, text/cache-manifest"
This seems to work fine when I only need to target W3SVC/1.
I need to write an update script that will make sure that any sites on a given IIS6 installation have the proper mime type configured. I could either add the mime type to each individial site or at the global level. I need to do this programmatically and would like to use adsutil.vbs if at all possible.
I think the easier way will be to just amend the mime types on each server, you need only do it once for the change to cascade down to each website, why are you trying to rewrite the .vbs mime type though? you might be better off creating a custom one.
Or you could set the change in the Metabase for IIS, you just need to set the enable direct metabase edit to true on each server then make the changes though code.
You could use ADSI and powershell 2.0.
$adsiPrefix = "IIS://$serverName"
$iisPath = "W3SVC"
$iisADSI = [ADSI]"$adsiPrefix/$iisPath"
$site = $iisADSI.Create("IISWebServer", $script:webSiteNumber)
$xapMimeType = New-Object -comObject MimeMap
SetCOMProperty $xapMimeType "Extension" ".xap"
SetCOMProperty $xapMimeType "MimeType" "application/x-silverlight-app"
$site.Properties["MimeMap"].Add($xapMimeType)
$site.SetInfo()
$site.CommitChanges()
function SetCOMProperty($target, $member, $value) {
$target.psbase.GetType().InvokeMember($member, [System.Reflection.BindingFlags]::SetProperty, $null, $target, $value)
}
来源:https://stackoverflow.com/questions/1910658/how-can-i-set-global-mime-types-for-iis6-programmatically