Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8923573
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:09:41+00:00 2026-06-15T07:09:41+00:00

I have a powershell function inside a file myfunc.ps1 function Set-Util ($utilPath ) {

  • 0

I have a powershell function inside a file myfunc.ps1

function Set-Util ($utilPath ) {

    if(Test-Path($utilPath) ){
      $fullPath = Join-Path -Path $utilPath "util.exe"
      set-alias MyUtil $fullPath
      #echo  "Path set to $fullPath"
    }else {
        throw  (" Error: File not found! File path '$fullPath' does not exist.")
    }
}

and I dot call it from command line with

. .\myfunc.ps1

then call

Set-Util somedirectory

The alias is being set correctly in the function, but I can’t access it out here with

MyUtil

Should I export the alias because the scope is only in the method?
I tried doing so with
Export-ModuleMember but got an error saying the cmdlet can only be called from insdie a module.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T07:09:42+00:00Added an answer on June 15, 2026 at 7:09 am

    You can’t do that because the alias won’t be set until the function is called, and when the function is called the alias is scoped to the function scope, so when the function finishes running – the alias is gone.

    If you want the alias to survive, specify use scope parameter with a value of ‘global’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Powershell script file called ExecutBizTalkAppMSI.ps1 This contains a single function called
I have a PowerShell module called Test.psm1. I want to set a value on
I have a function that lets me write the file-path of files to a
I have a script like so: test.ps1 param ( $name, $age ) function load-parameters()
I have this PowerShell cmdlet: function Test-ParameterBinding { # # .SYNOPSIS # Tests parameter
I have a test powershell V2 script that looks like this: function test_args() {
Is there a quick way to join paths like the Join-Path function in Powershell?
In my build script, I have a helper powershell function as below: function set-connectionstring
I have a function in a powershell script that is supposed to untar my
How to call function using parameters in powershell with parenthesis. I have as example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.