search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Getting frequently used Mime Types with Powershell
Posted in Windows Powershell | No Comment | 2,715 views | 14/07/2012 22:00

If you need to get a mimetype of extension, then you can use this function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function Get-MimeType
{
param ($Extension)
 
	switch ($Extension) 
	{ 
		.ps1 {"text/ps1"}
		.psxml {"text/psxml"}
		.psapi {"text/psxml"}
		.posh {"text/psxml"}
		.html {"text/html"} 
		.htm {"text/html"} 
		.php {"text/php"} 
		.css {"text/css"} 
		.jpeg {"image/jpeg"} 
		.jpg {"image/jpeg"}
		.gif {"image/gif"}
		.ico {"image/x-icon"}
		.flv {"video/x-flv"}
		.swf {"application/x-shockwave-flash"}
		.js {"text/javascript"}
		.txt {"text/plain"}
		.rar {"application/octet-stream"}
		.zip {"application/x-zip-compressed"}
		.rss {"application/rss+xml"}
		.xml {"text/xml"}
		.png {"image/png"}
		.mpg {"video/mpeg"}
		.mpeg {"video/mpeg"}
		.mp3 {"audio/mpeg"}
		.woff {"application/x-font-woff"}
		default {"text/html"}
	}	
}

It’s simple but covers what you are really looking for.



Leave a Reply