Skip to content

Instantly share code, notes, and snippets.

@StartAutomating
Created October 29, 2025 03:31
Show Gist options
  • Select an option

  • Save StartAutomating/afa2be23713baf9465cf73661f755af4 to your computer and use it in GitHub Desktop.

Select an option

Save StartAutomating/afa2be23713baf9465cf73661f755af4 to your computer and use it in GitHub Desktop.
Gist Get the Common Mime Types
<#
.SYNOPSIS
Get common mime types
.DESCRIPTION
Gets the common mime types according to MDN
.LINK
https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
#>
if (-not $script:CommonMimeTypes) {
$script:CommonMimeTypes = Invoke-RestMethod https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/MIME_types/Common_types
}
if ($script:CommonMimeTypes -match "<table[\s\S]+?</table>") {
$tableXml = $matches.0 -as [xml]
$ExtensionContentType = [Ordered]@{}
foreach ($row in $tableXml.table.tbody.tr) {
foreach ($extension in $row.td[0].code) {
$contentType = @($row.td[2].code)[0]
$ExtensionContentType[$extension] = $contentType
}
}
}
$ExtensionContentType
return
# Bonus points, export as JSON
$ExtensionContentType | ConvertTo-Json -Depth 3 |
Set-Content ./ExtensionContentTypes.json
# Bonus points, make a .psd1 file
@(
'@{'
foreach ($keyValuePair in $ExtensionContentType.GetEnumerator()) {
" '$($keyValuePair.Key)' = '$($keyValuePair.Value)'"
}
'}') | Set-Content ./ExtensionContentTypes.psd1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment