I created a PowerShell script to set aliases for a PowerShell session. When I run the script and try the alias, I get the error saying that the alias isn't recongized. How can I use the aliases that are set by the script?


Run the script using Dot sourcing operator:

. Dot sourcing operator
Runs a script in the current scope so that any functions, aliases, and variables that the script creates are added to the current scope.

. c:\scripts\sample.ps1

Note: The dot sourcing operator is followed by a space. Use the space to distinguish the dot from the dot (.) symbol that represents the current directory.

In the following example, the Sample.ps1 script in the current directory is run in the current scope.

. .\sample.ps1
  • Is that using the absolute path, not a relative path? – thecomputerguru Dec 10 '19 at 23:08
  • The former example . c:\scripts\sample.ps1 shows an absolute path while the latter example . .\sample.ps1 shows a relative one. – JosefZ Dec 11 '19 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.