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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:09:31+00:00 2026-05-31T14:09:31+00:00

I have a script like so: test.ps1 param ( $name, $age ) function load-parameters()

  • 0

I have a script like so:

test.ps1

param (
    $name,
$age
)

function load-parameters()
{
$name = "Bob"
$age = "23"

Write-Host "name: " $name
Write-Host "age: " $age
}

load-parameters
Write-Host "name: " $name
Write-Host "age: " $age

Except instead of name and age, i have about 10 parameters that i’m loading and initializing inside load-parameters.

The problem I am trying to solve is trying to preserve the values of the initialization of (what i think are) global scope functions inside the script.

The function above returns:

name:  Bob
age:  23
name:
age:

Are the local edits hardwired when you change them into functions? it looks like the implementation is that parameters are being passed by copy to functions you write inside a script.

I realize I can get around this by passing the variables by reference (if there is even a thing in powershell functions), but that would be ugly given the number of parameters i need to pass. is there a way to specify the scope of the variable when i’m doing the assignment inside function “load-parameters”?

  • 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-31T14:09:32+00:00Added an answer on May 31, 2026 at 2:09 pm

    It is not super clear what you want to achieve with the load parameters. What you are trying to do maybe solved with default values for the parameters for your script:

    param (
        $name = "Bob",
        $age = "23"
    )
    

    Another option for what you are trying is to use the variables with script scope:

    $script:name = "Bob"
    

    So in the functions you can do something like:

    function load-parameters
    {
    $script:name = "Bob"
    $script:age = "23"
    
    Write-Host "name: " $name
    Write-Host "age: " $age
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that looks like this: var test = { something: function(m){
I have a simple test bash script which looks like that: #!/bin/bash cmd=rsync -rv
I have a NAnt script like below: <if test=${a}>${b}> <call target=target/> </if> What I
I have a NAnt script like below: <target name=Init unless=${target::has-executed('Init')}> What I want is
I have a script that looks like this #!/bin/bash function something() { echo hello
Say, I have a shell script like this: utils.sh function getDir { echo "DirName"
i have script like this. function getContactLastDateOfDeparture(contactId) { $.get( '/transaction/ajaxGetContactLastDateOfDeparture/'+contactId, '', function(data){ alert(data); return
I have script like this : fullscript.sh if [ ! -f /opt/laks/linux-2.6.33.2.tar.bz2 ] then
I have a script like that genhash --use-ssl -s $IP -p 443 --url $URL
If I have a script tag like this: <script id = myscript src =

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.