So I was wondering if there is a specific way to change/edit a mime type in IIS 7.5 using powershell?
So far I have come across solutions to add mimetypes such as:
and a couple of others that have books being referenced but those books do not contain any information on that, i checked.
It seems like using the
Add-WebConfigurationProperty is used, but when i use this method for an existing mimetype then i will receive an error that is related to a duplicate item entry (since its already in there), so this method is out of the window.
I attempted to use the
Set-WebConfigurationProperty instead but that resulted in it deleting ALL the existing mimetype entries and just leaving one of it.
So does anyone have a suggestion or perhaps knows the correct method of doing this? I also considered doing something like first deleting the entry and then adding it, the only problem is you will need to know both the mimetype fileExtension and the mimeTypes (i.e text/XML etc). So I assume I would need to first get both properties using the
getwebconfigproperty method, then delete it by parsing the values from it into the
delete-webpropconfig function and then add it... But going three steps just to set a mimetype seems excessive..
From what I understand, the appcmd.exe set config "values and params here" method will pretty much just straight-out do it.. the issue with this however is that unfortunately we cannot use it. And yes I understand I can make the powershell execute the appcmd command unfortunately this is not a viable option. I have tried googling and reading in books for solutions but have not come up with an answer so far on why
set-webconfigurationproperty method deletes all other mimetype entries
add-webconfigurationproperty will not allow me to perform it and throws an "error duplication" message
3) a working solution to do this in 1 line with powershell.