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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With