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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:01:41+00:00 2026-05-30T06:01:41+00:00

PowerShell provides a simple technique to view the contents of a function, e.g. Get-Content

  • 0

PowerShell provides a simple technique to view the contents of a function, e.g.

Get-Content function:MyFuncName   # (A)

or equivalently

(Get-ChildItem function:MyFuncName).definition    # (B)

where MyFuncName is the name of my function. That is great for simple functions (i.e. functions that use only base language constructs and do not call other functions). But consider the function foo shown below that contains a call to the function bar. In a typical scenario these would both be contained in the same module whose public API consists solely of the function foo and thus it is the only function exported.

function foo ()
{
    $p = bar "here"
    "result is '$p'"
}
function bar ([string] $s)
{
    $s + $s
}
Export-ModuleMember foo

Is there any way to view the nested, non-exported functions (like function bar) within another function in a fashion comparable to (A) or (B) above? (That is, without opening the .psm1 file in an editor 🙂

  • 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-30T06:01:42+00:00Added an answer on May 30, 2026 at 6:01 am

    I’m not sure if you can do it for a particular function in a module but you can do it for the whole module:

    Import-Module C:\Test.psm1
    (Get-Module Test).Definition
    

    I think the fact that function foo calls function bar is not known until runtime.

    Update

    Where there’s a will, there’s a way 🙂 Here’s how you can access private module members. Invoke the module with a scriptblock. Inside the scriptblock the private members are visible.

    Import-Module C:\Test.psm1
    $module = Get-Module Test
    & $module { (get-item function:bar).Definition }
    

    Thanks to PowerTips 🙂 http://powershell.com/cs/blogs/tips/archive/2009/09/18/accessing-hidden-module-members.aspx

    Update 2

    After finding the little PowerTip snippet I was kinda curious what was really going on… The snippet uses the call operator & with two arguments.

    1. The module object (System.Management.Automation.PSModuleInfo)
    2. A script block

    So what’s really going on is the Invoke method of the PSModuleInfo type is being called. The code in the script block runs within the same session state as the rest of the module code so it has access to the private members. This code does the exact same thing as the PowerTip snippet:

    $module = Get-Module Test
    $module.Invoke( { (get-item function:bar).Definition } )
    

    Check out the invoke method here: http://msdn.microsoft.com/en-us/library/system.management.automation.psmoduleinfo.invoke(v=vs.85).aspx

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

Sidebar

Related Questions

I have a simple PowerShell script that uses WMI to create a web site
I have a simple powershell script on windows 7 that doesn't work properly. (this
I have a function that lets me write the file-path of files to a
I have a PowerShell script that configures web site and web application settings in
I was listening to the podcast about PowerShell 2.0 that Scott Hanselman did .
I know there is a project called sqlpsx and it provides some powershell based
I'm trying to write a PowerShell script that will automate my IIS website deployments.
I developed a powershell application on an XP box that made an OLEDB connection
Can anyone provide a link to a PowerShell module which provides automation support for
I want to write a Powershell script that will validate a large number of

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.