Home ยป PowerShell ยป How to Import Alias in PowerShell

How to Import Alias in PowerShell

Import-Alias cmdlet in PowerShell imports an alias list from the specified file. Use the Scope parameter to specify the scope into which the alias list is imported.

Using the Force parameter of Import-Alias, you can import an alias that is read-only or already defined in the current scope.

In this article, we will discuss how to use the Import-Alias cmdlet to import the alias list from the file.

PowerShell Import-Alias

Import-Alias imports the alias information from the specified file.

Syntax

Import-Alias
      [-Path] <String>

      [LiteralPath] <String>
      [-Scope <String>]
      [-PassThru]
      [-Force]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Parameters

-Path: Specify the file path that includes the alias information.

-LiteralPath: Specify the path to the file that includes the alias information. The value of the LiteralPath parameter is used exactly as it is typed.

-Scope: Specifies the scope into which alias information will be imported. By default scope value is Local. However, acceptable values for this parameter are Global, Local, or Script.

-Force: Allows the Import-Alias cmdlet to import the alias list that is read-only or already defined.

Import Alias List From a File

Use the Import-Alias cmdlet in PowerShell to import alias information from the file.

Import-Alias -Path D:\PS\alias.txt

In the above PowerShell script, Import-Alias uses the Path parameter to specify the file to be imported. It imports alias information from the file.

Conclusion

I hope the above article on how to import alias in PowerShell is helpful to you.

The Import-Alias does not overwrite existing aliases by default. If you want to overwrite an existing alias, use the Force parameter.

You can refer to the related articles on Alias in PowerShell.

New-Alias

Get-Alias

Set-Alias

Remove-Alias

Export-Alias

PowerShell Set Alias Permanent

PowerShell Alias Function

PowerShell Parameter Alias

You can find more topics about PowerShell Active Directory commands and PowerShell basics on the ShellGeek home page.