What is MIME type "text/x-powershell"?

A MIME type is a string that tells browsers and other tools how to handle a particular kind of file.

text/x-powershell is a MIME type that marks files as PowerShell scripts. It tells the system that the file contains commands for automation and task management.


This MIME type informs programs and interpreters that the text holds a PowerShell script. It ensures that the code is treated correctly when run by the PowerShell engine.



Files like PS1 and PSM1 typically use this MIME type. They are central to executing scripts and organizing code in modular ways.


For more details on PowerShell, visit the Microsoft PowerShell Documentation.

Associated file extensions

Usage Examples

HTTP Header

When serving content with this MIME type, set the Content-Type header:


    Content-Type: text/x-powershell    
  

HTML

In HTML, you can specify the MIME type in various elements:


    <a href="file.dat" type="text/x-powershell">Download file</a>    
  

Server-side (Node.js)

Setting the Content-Type header in Node.js:


    const http = require('http');    
    
    http.createServer((req, res) => {    
      res.setHeader('Content-Type', 'text/x-powershell');    
      res.end('Content here');    
    }).listen(3000);    
  

Associated file extensions

FAQs

How do I configure IIS to serve PowerShell scripts?

In IIS Manager, navigate to MIME Types and add a new entry with the extension .ps1 and the MIME type text/x-powershell. By default, IIS often blocks these files for security reasons, so you must explicitly allow them if you intend to serve scripts for download.

Will web browsers execute files with the text/x-powershell content type?

No, web browsers do not have a built-in engine to execute PowerShell scripts. Most browsers will either display the code as plain text or prompt the user to download the file to their local machine for execution via the PowerShell console.

What is the difference between text/x-powershell and application/x-powershell?

Both are non-standard types, but text/x-powershell is generally preferred because it indicates the file is human-readable source code. Using the text/ category allows browsers to preview the content inline, whereas application/ usually forces a "Save As" download prompt.

How do I add support for this MIME type in Nginx?

You can add the type definition to your mime.types file or directly inside a server block configuration. Use the directive types { text/x-powershell ps1; } to ensure Nginx serves .ps1 files with the correct headers.

Are there security risks associated with serving text/x-powershell files?

Yes, publicly serving scripts can reveal internal system logic, network paths, or accidentally hardcoded credentials. Always review code for sensitive data before allowing public access, and consider using authentication to restrict downloads.

Why does the MIME type start with x-?

The x- prefix indicates that text/x-powershell is a non-standard type not officially registered with the IANA. Despite the lack of official registration, it is the widely accepted convention for identifying PowerShell code on the web.

Can I use this MIME type for PowerShell modules?

Yes, this MIME type is appropriate for both standard scripts and module files like .psm1. It correctly identifies the content as PowerShell syntax regardless of whether it is a standalone script or a module library.

General FAQ

What is a MIME type?

A MIME (Multipurpose Internet Mail Extensions) type is a standard that indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

MIME types are important because they help browsers and servers understand how to process a file. When a browser receives a file from a server, it uses the MIME type to determine how to display or handle the content, whether it's an image to display, a PDF to open in a viewer, or a video to play.

MIME types consist of a type and a subtype, separated by a slash (e.g., text/html, image/jpeg, application/pdf). Some MIME types also include optional parameters.

How do I find the MIME type for a file?

You can check the file extension or use a file identification tool such as file --mime-type on the command line. Many programming languages also provide libraries to detect MIME types.

Why are multiple MIME types listed for one extension?

Different applications and historical conventions may use alternative MIME identifiers for the same kind of file. Showing them all helps ensure compatibility across systems.