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 3996456
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:16:53+00:00 2026-05-20T07:16:53+00:00

Ok, so I have a file called functions.ps1 that contains only function code: something

  • 0

Ok, so I have a file called functions.ps1 that contains only function code: something like this:

##--------------------------------------------------------------------------
##  FUNCTION.......:  some-Function1
##  PURPOSE........:  
##  EXAMPLE........:  
##  REQUIREMENTS...:  PowerShell 2.0
##  NOTES..........:  
##--------------------------------------------------------------------------
Function Some-Function1
{
Code goes here
}
##--------------------------------------------------------------------------
##  FUNCTION.......:  some-Function2
##  PURPOSE........:  
##  EXAMPLE........:  
##  REQUIREMENTS...:  PowerShell 2.0
##  NOTES..........:  
##--------------------------------------------------------------------------
Function Some-Function2
{
Code goes here
}

Now, the last function in this file (and the one relevant to my issue) is this:

##--------------------------------------------------------------------------
##  FUNCTION.......:  List-Functions
##  PURPOSE........:  
##  EXAMPLE........:  
##  REQUIREMENTS...:  PowerShell 2.0
##  NOTES..........:  
##--------------------------------------------------------------------------
function List-Functions
{
    $func_1 = "##  FUNCTION"
    $func_2 = Get-Content \\Server\scripts\functions.ps1
    $func_2 | select-string -pattern $func_1 | foreach {write-host $_.line}
}

The idea here is that from the console I can dot source the function.ps1 file, and by firing off List-Functions, I’ll get a list of all the functions in the functions file.

Except when run, List-Function returns something like this:

##  FUNCTION.......:  some-Function1
##  FUNCTION.......:  some-Function2
##  FUNCTION.......:  List-Functions
$func_1 = "##  FUNCTION"

Everything is cool, except that last bit of code. I know that it’s only matching the pattern I’ve given it, but it’s annoying me something furious.

I know my Regex-fu is weak, and I tried altering List-Functions to filter that bit out, but I am having no joy. Can anyone point out what I can do to get this working correctly?

My solution (which is ugly), was to change List-Functions to this:

##--------------------------------------------------------------------------
##  FUNCTION.......:  List-Functions
##  PURPOSE........:  
##  EXAMPLE........:  
##  REQUIREMENTS...:  PowerShell 2.0
##  NOTES..........:  
##--------------------------------------------------------------------------
function List-Functions
{
    $char = [char] '#'
    $func_1 = $char + $char + "  FUNCTION"
    $func_2 = Get-Content \\server\scripts\functions.ps1
    $func_2 | select-string -pattern $func_1 | foreach {write-host $_.line}
}

I told you it was ugly, but it works 😉

  • 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-20T07:16:54+00:00Added an answer on May 20, 2026 at 7:16 am

    You need to match only lines that begins with the string ##. So change your regex to

    $func_1 = "^##  FUNCTION"
    

    Better solution: Consider using modules. Store your functions Some-Function1 and Some-Function2 to file MyModule.psm1. Then:

    PS> Import-Module d:\MyModule.psm1
    # or with -DisableNameChecking to suppres warning messages
    PS> Import-Module d:\MyModule.psm1 -DisableNameChecking
    
    PS> Get-Command -module MyModule | Select -expand Name
    Some-Function1
    Some-Function2
    

    How you can try the regex:

    @'
    ##--------------------------------------------------------------------------
    ##  FUNCTION.......:  some-Function1
    ##--------------------------------------------------------------------------
    Function Some-Function1
    {
    Code goes here
    }
    ##--------------------------------------------------------------------------
    ##  FUNCTION.......:  some-Function2
    ##--------------------------------------------------------------------------
    Function Some-Function2
    {
    Code goes here
    }
    ##--------------------------------------------------------------------------
    ##  FUNCTION.......:  List-Functions
    ##--------------------------------------------------------------------------
    function List-Functions
    {
        Get-Content d:\temp\sotest.ps1 | 
            select-string -pattern "^##  FUNCTION" | 
            Select -exp Line
    }
    '@ | Set-Content d:\temp\sotest.ps1
    . d:\temp\sotest.ps1
    List-Functions
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jQuery code. I have called an Ajax function file, file.php, that
So i have this class that includes some custom functions named class.php I have
I have a function called: void initializeJSP(string Experiment) And in my MyJSP.h file I
I have a file called main.py and a file called classes.py main.py contains the
I'm trying to work this out. In my project, i have a file called
For example, suppose I have a batch file called 'test.cmd' and it simply contains:
I have a function called init on my website in an external file called
I have a seperate PHP file I include that has a several important functions
We have a c file called dbookpy.c, which will provide a Python binding some
Say I have file.php with three functions and an echo statement: function one() {

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.