File formats used by PowerShell
Table of Contents
I. Introduction
When using PowerShell, you'll need to manipulate files of various types, in different formats. In this chapter, we'll look at PowerShell's associated file extensions, as well as other complementary extensions.
II. File formats: PS1, PSD1, PSM1, etc.
PowerShell supports various file formats, including those corresponding to the following extensions: ps1, psd1, psm1, but also ps1xml. These are the official extensions, and apply to both Windows PowerShell and PowerShell.
The main extension is ".ps1". In fact, this is the extension used by PowerShell scripts, so each of your scripts will have to use this extension. The fact that it's "ps1" is rather misleading: you'd think there'd be some information about the PowerShell version, but that's not the case. No matter whether a script contains PowerShell 1.0 or PowerShell 7.0 code, its extension will be ".ps1".
Next, we have the ".psd1" extension, referring to configuration files or data files. In other words, these are files formatted according to PowerShell structure and syntax, which a script can read to retrieve information.
The ".psm1" extension is used for PowerShell module files, which are scripts containing functions, variables and commands intended to be shared and reused in other PowerShell scripts.
The ".ps1xml" extension is used to define the default display of objects in the PowerShell console. These files allow you to customize the way information is presented and formatted when displayed on screen.
III. File formats: CSV, XML, JSON, etc.
PowerShell is able to read and write data in other formats, which is very useful for processing data sets or defining configuration files. Popular extensions include: CSV, XML, JSON, even TXT and YAML. Here are a few words about these"universal" file formats, which are used far beyond PowerShell.
The ".csv" extension stands forComma-Separated Values( CSV ), a file format in which data is structured using a separator character. This is a very simple file format used to store data, such as spreadsheet or database data. Each line of the file represents a separate data record, with each value (field) in the line separated by a comma, semicolon or tab, depending on how the file was generated.

The ".xml" extension is used for XML (Extensible Markup Language) files, which is a markup language used to store data. XML files are structured in such a way as to be understandable by both humans and machines, making them useful in a wide variety of applications, including PowerShell.
The ".json" extension for JSON (JavaScript Object Notation) files is also supported by PowerShell. In fact, JSON is a format often used when data is sent from a server to a web client. Today, JSON is one of the most popular formats for structuring data in many web and mobile applications.
IV. Conclusion
When you're writing PowerShell scripts in a professional context, you're bound to be confronted with the need to manipulate files in some or all of the formats discussed in this chapter. Various cmdlets are available to meet this need. For example, the"Import-CSV" cmdlet lets you import the contents of a CSV file into PowerShell. Conversely, the"Export-CSV" cmdlet can be used to export data to an output file in CSV format. We'll have a chance to put this notion into practice later on.
