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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:42:35+00:00 2026-06-17T00:42:35+00:00

I have a module that has the following function. Test-Module.psm1 function Do-Stuff { [CmdletBinding()]

  • 0

I have a module that has the following function.

Test-Module.psm1

function Do-Stuff
{
    [CmdletBinding()]
    param($Stuff)
    Write-Debug 'Doing stuff!'
    Write-Host $Stuff
}

And I have a script that imports the module.

Test-Script.ps1

[CmdletBinding()]
param($Stuff)

Import-Module ./Test-Module.psm1

Write-Host 'About to do stuff.'
Do-Stuff -Stuff $Stuff
Write-Host 'Just did some stuff.'

But when I call the script the -Debug flag is not respected in the Do-Stuff function.

PS > .\Test-Script.ps1 -Stuff 'foobar'
About to do stuff.
foobar
Just did some stuff.

I recall seeing something on StackOverflow recently that discussed this very problem and suggested you could have the module examine the parameters up through the call stack to determine if it should implement the debugging or not. I can’t find it now though and I’m not sure I understood how to implement at the time anyway.

How can I implement something like this, or something different that achieves the same goal.

  • 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-17T00:42:36+00:00Added an answer on June 17, 2026 at 12:42 am

    one way may be to add this code on top of you module :

    if ((get-pscallstack |select -last 2 |select -expand arguments -first 1) -match "verbose"){$verbosepreference="continue"}
    if ((get-pscallstack |select -last 2 |select -expa arguments -first 1) -match "debug"){ $debugpreference="continue"}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a Zend application that has these following modules: Users Shop etc... Front
Let's say that I have a module that has a Queue in it. For
I have a directory tmp that has 3 test node.js modules [mod0.js, mod1.js, mod2.js]
I have a Javascript module the following Javascript: EntryController = function$entry(args) { MainView(); $('#target').click(function()
I have a unmanaged C++ function with the following signature: int function(char* param, int
I have to write a testing module and have c++-Background. That said, I am
I have an admin module, that has a file input filed, where I'd like
i have the following module and i would like to test connection. how do
I have a python module that I've made that contains regular function defintions as
I have one module called UserProvider that looks like this var UserProvider = function(db)

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.