Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell: Possible to Determine a File's MIME Type?

Is it possible for PowerShell to determine what a given file's type is? For example, if I pass it a path of C:\Foo.zip, can I have it determine that the file at that path is, in fact, a zip file and not something else?

like image 594
Nick Avatar asked Jul 28 '12 05:07

Nick


1 Answers

If you have .NET 4.5+, you can use the static method System.Web.MimeMapping.GetMimeMapping:

> Add-Type -AssemblyName "System.Web"
> [System.Web.MimeMapping]::GetMimeMapping("C:\foo.zip")
application/x-zip-compressed

Credit goes to this answer to a similar question about .NET.


Edit: Misread the question. GetMimeMapping returns the MIME type by extension, it doesn't analyze the contents.

like image 135
Helen Avatar answered Oct 04 '22 12:10

Helen