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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:46:49+00:00 2026-06-17T16:46:49+00:00

I have a main script, where a few constants are defined. I then have

  • 0

I have a main script, where a few constants are defined. I then have a module (psm1) to include helper functions. The details are:

In the main script, I have imported the module as an object:

$cud2ADhleper = Import-Module -Force $cud2ADhelperModule -AsCustomObject

In the module, I have two variables,

[string]$SQLServer = $null

Function SetSQLServerAddr ([string] $name)
{
    $SQLServer = $name
}
Function GetSQLServerAddr
{
    return $SQLServer
}

My understanding is that because I am not exporting $SQLServer from the module, this variable should be local, and I should be able to Set/Get it.

It turns out otherwise. After I called SetSQLServerAddr ([string] $name), then callling GetSQLServerAddr returns $null. What did I miss?

  • 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-17T16:46:49+00:00Added an answer on June 17, 2026 at 4:46 pm
    Function SetSQLServerAddr ([string] $name)
    {
        $SQLServer = $name
    }
    

    That creates a new local $SQLServer in the scope of that function.

    If you want to update a variable at module (.psm1) scope then you need to prefix the name to indicate that:

    Function SetSQLServerAddr ([string] $name)
    {
        $script:SQLServer = $name
    }
    

    For more on scopes see get-help about_scopes.

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

Sidebar

Related Questions

I have a script which has a few functions inside it which the main
I have a simple main shell script that does a few prep things and
In Python I have a module myModule.py where I define a few functions and
Let's assume I have a main script, main.py, that imports another python file with
In my main script, I am doing some archive manipulation. Once I have completed
I have a vm.py in the same directory as the main() script ( getdata.py
I have a html main.html as given ----- main.html---------------- <title>FlexTrail</title> <script src=main.js></script> <frameset rows='200,200'>
Say I have a PHP script, //main.php -> PID = 1002 <?php exec('ProcessOne'); exec('ProcessTwo');
The main problem is square-space builds their forms with java-script (YUI). They have are
I have a JS code like this <script type=text/javascript> $(document).ready(function(){ $('.main').on('click', '.block', function (){

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.