EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login

PowerShell File Extension

Home » Data Science » Data Science Tutorials » PowerShell Tutorial » PowerShell File Extension

PowerShell File Extension

Introduction to PowerShell File Extension

Generally, when someone thinks of PowerShell and the file extension, only .ps1 comes to their mind. It is not possible for 95% of the users that there are other file extensions associated with PowerShell. This article will throw the limelight on those file extensions.

3 Different PowerShell File Extension

Following are some of the other extensions that are associated with PowerShell:

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Different PowerShell File Extension

  • .psm1
  • .psd1
  • .ps1xml

1. .psm1 Files

This represents a PowerShell module file. A module is a collection of cmdlets, variables, functions, and workflows put together as a package. Modules were first introduced in PowerShell version 2. Modules are generally stored in the following two primary locations.

  • %windir%\system32\WindowsPowerShell\v1.0\Modules this is the location for system-wide modules available to any user in the system.
  • %USERPROFILE%\Documents\WindowsPowerShell\Modules.

Each module has a dedicated folder in which it is saved. It also contains a psd1 file called Module Manifest. The manifest file contains the setting of the module like the version of PowerShell, author, and other settings. The list of available modules can be got by running the Get-Module -ListAvailable cmdlet.

A module is generally comprised of four basic blocks.

  • A piece of code
  • Assemblies
  • Manifest file
  • A directory to contain the above three.

Types of Modules

There are four different types of modules:

different types of modules

  • Script Modules: It contains PowerShell variables, functions, and workflows.
  • Binary Modules: It is a compiled .net framework code written in a language like c#.
  • Manifest Module: It doesn’t have any direct code, instead it uses a manifest file to use features of other modules.
  •  Dynamic Modules: These modules are not stored anywhere, instead they are generated dynamically by the New-Module cmdlet.

2. .psd1 Files

These files are manifest files. It describes the content of the module and dictates the processing of the module. It is a text file with a hashtable that has a key-value pair. A manifest file is linked to a module by naming the manifest the same as a module and storing the manifest in the module’s root directory. The following are some of the elements that will be present in a manifest file. The New-ModuleManifest cmdlet is used to create a new module manifest file.

  •  RootModule: Its type is a string and it represents the script module or binary module that is associated with the manifest.
  •  ModuleVersion: Its type is version. It denotes the version of the module to which the manifest file is associated.
  • GUID: Its type is GUID, it denotes the unique identifier of the module.
  •  Author: Its type is a string and it represents the author of the module. If the value is not specified, the New- ModuleManifest uses the current user name as the author’s name.
  • Description: Its type is a string and it provides a description of the module’s functionality.
  • CLRversion: Its type is version and it denotes the minimum CLR version that is used to run or use the module.
  •  RequiredModules: Its type is an object and it denotes the other modules that need to be loaded before importing this module.
  • RequiredAssemblies: Its type is a string and it denotes the other assemblies that need to be loaded before importing this module.

3. .ps1xml Files

It is the extension for PowerShell XML files. These are configuration files that contain the details about how the output is displayed and other formatting related styles that are being used. .ps1xml files are automatically installed with PowerShell. They are digitally signed to prevent it for editing as editing these files requires immense knowledge and any changes made to them can have a huge impact. Generally, the XML files are used to extend the functionality of PowerShell objects.

There are three ways in which extended data type can be loaded into a PowerShell session as follows:

Popular Course in this category
Sale
Shell Scripting Training (4 Courses, 1 Project)4 Online Courses | 1 Hands-on Project | 18+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (8,751 ratings)
Course Price

View Course

Related Courses
All in One Data Science Bundle (360+ Courses, 50+ projects)Data Visualization Training (15 Courses, 5+ Projects)
  • They are either loaded automatically by PowerShell.
  • When types.psxm1 file modules are imported to the current session.
  • Using Update-TypeData Cmdlet.

There are many in-built XML files in PowerShell. They are present in the home directory and are loaded automatically to every session. To add new properties or methods to an existing PowerShell object, it must be done via the types.ps1xml file.

To add a new .ps1xml file below are the steps:

  • Copy an existing .ps1xml file.
  • Make the changes and save the file with the extension .ps1xml.
  • It is advisable to save the file in the home directory though it is not mandatory.
  • Use the Update-TypeDate cmdlet to include the file in the current session.

Examples of PowerShell File Extension

Given below are the examples of PowerShell File Extension:

Example #1: Creation of new .psm1 file

Code:

Write-Host "Demo of module creation"
param(
[string[]] $name,
[string[]] $age,
[string[]] $phonenumber,
[string[]] $address
)
function function1 ()
{
Write-Host "Sample function1"
}
function function2 ()
{
Write-Host "Sample function2"
}
function function3 ()
{
Write-Host "Sample function3"
}
Export-ModuleMember -Function function1
Export-ModuleMember -Function function2
Export-ModuleMember -Function function3

Save the above code as .psm1 file in any location but it is advisable to store in the location the same as PowerShell.

To import the above file into a PowerShell session using the below cmdlet.

Import-Module C:\Vignesh\Script\test.psm1 -ArgumentList "vignesh","10","454545","sadsad"

Once the module is imported the functions inside the module can be accessed.

Output:

PowerShell file extension 1

Example #2: Creation of .psd1 File

Code:

@{
Author ='Vignesh Krishnakumar'
CompanyName='test company'
Copyright ='All rights are subject to test company'
GUID = 'b000090c-dzzz-4340-9df4-3b8326000000'
ModuleVersion = '6.6.6'
Description='Test Manifest file'
}

Save the above as a .psd1 file.

To import the manifest file, use the below cmdlet:

Import-PowerShellDataFile -Path ‘C:\Vignesh\Script\test.psd1’

Output:

PowerShell file extension 2

Conclusion

Thus, the article covered a few of the commonly used file extension types available in PowerShell other than .ps1. It covered in detail about .psd1, .psm1 and .ps1xml file extension in detail along with their usage and functionalities. The article also showed examples of creating a module file, accessing a module, creating a manifest file, and importing them.

Recommended Articles

This has been a guide to PowerShell File Extension. Here we discuss the introduction, 3 different PowerShell file extensions, and examples. You may also have a look at the following articles to learn more –

  1. PowerShell Get-ChildItem
  2. PowerShell Move-Item
  3. What is Bash Scripting?
  4. Batch Scripting Commands

All in One Data Science Bundle (360+ Courses, 50+ projects)

360+ Online Courses

50+ projects

1500+ Hours

Verifiable Certificates

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
PowerShell Tutorial
  • Basics
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

Special Offer - Shell Scripting Course Learn More