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

  • Home
  • SEARCH
  • 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 6971261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:49:02+00:00 2026-05-27T16:49:02+00:00

I have two questions here, why does the following function in a script not

  • 0

I have two questions here, why does the following function in a script not recognized when I run the script:

Script:

$pathN = Select-Folder
Write-Host "Path " $pathN

function Select-Folder($message='Select a folder', $path = 0) { 
  $object = New-Object -comObject Shell.Application  

  $folder = $object.BrowseForFolder(0, $message, 0, $path) 
    if ($folder -ne $null) { 
        $folder.self.Path 
    } 
} 

I get error:

The term 'Select-Folder' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try aga

in.

But if I load and run it in the Windows Powershell ISE, it will give me the error the first time, and then act like it has “registered” the function and work after that.

And in case it is a procedural issue, I have tried listing the function at the top with no better luck.

Note I have tried simple functions like:

Write-host "Say "
Hello

function Hello {
  Write-host "hello"
}

With the same exact results/error, it complains that Hello is not function….

Also, it still won’t every work just running the script in powershell (only in ISE after the first initial attempt).

  • 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-05-27T16:49:03+00:00Added an answer on May 27, 2026 at 4:49 pm

    You need to declare your Select-Folder function before you try to use it. The script is read from top to bottom, so on the first pass when you try to use Select-Folder it has no idea what that means.

    When you load it into the Powershell ISE it’ll find out what Select-Folder means on the first run, and it’ll still know that the 2nd time you try to run it (so you won’t get the error then).

    So if you change your code to:

    function Select-Folder($message='Select a folder', $path = 0) { 
      $object = New-Object -comObject Shell.Application  
    
      $folder = $object.BrowseForFolder(0, $message, 0, $path) 
        if ($folder -ne $null) { 
            $folder.self.Path 
        } 
    } 
    
    $pathN = Select-Folder
    Write-Host "Path " $pathN
    

    that should work each time you run it.

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

Sidebar

Related Questions

I have two questions: (1) I learned somewhere that -O3 is not recommended with
Ok, NHibernate question here. I have two objects that I would like to map
I have a question, here are two classes below: class Base{ public: virtual void
I have two questions: 1) How can I make an array which points to
I have two questions. Do realloc() and memcpy() copy the entries in an array
I have two questions: 1) I have a few global variables for my website
I have two questions: From personal experience, what free blog engine is the best
I have two questions about java.awt.Shape . Suppose I have two Shape s, shape1
I have two questions 1) my interface i have interface called IRegister and within
I have two questions. 1) Should you always use a using statement on a

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.