Windows Vista Forums

param VS dotsourcing
  1. #1


    Nicopilami Guest

    param VS dotsourcing

    hello, i would like to use some fonctions of a dot-sourced file and
    get all the parameters setted in the command line at the same time;


    how to make the following lines exist at the same time ?
    i've read that every dotsourced reference had to be located at the
    first line of the script, and the same things for the param command.



    For this reason, the following scriptblock doesn't work because param
    isn't at the first line...

    .. ./functions.ps1
    param(
    $computername=$null,
    [switch]$param1,
    [switch]$param1,
    [switch]$param1
    )





    and the following scriptblock doesn't work because the dotsourcing is
    not at the first line...


    param(
    $computername=$null,
    [switch]$param1,
    [switch]$param1,
    [switch]$param1
    )
    .. ./functions.ps1





    how should i do ???

    Bye
    Nico


      My System SpecsSystem Spec

  2. #2


    Brandon Shell Guest

    Re: param VS dotsourcing

    Param must be at the begining and there is no requirement for DoT sourcing
    that I know of.

    Your Second example worked for me except you had three [switch]$param1
    instead of 1/2/3.

    param(
    $ccomputername = $null,
    [switch]$param1,
    [switch]$param2,
    [switch]$param3
    )
    .. $pwd\bleh.ps1

    What is the problem you are having? Error?

    "Nicopilami" <n.chaussard@gmail.com> wrote in message
    news:1187621550.303710.233370@r34g2000hsd.googlegroups.com...
    > hello, i would like to use some fonctions of a dot-sourced file and
    > get all the parameters setted in the command line at the same time;
    >
    >
    > how to make the following lines exist at the same time ?
    > i've read that every dotsourced reference had to be located at the
    > first line of the script, and the same things for the param command.
    >
    >
    >
    > For this reason, the following scriptblock doesn't work because param
    > isn't at the first line...
    >
    > . ./functions.ps1
    > param(
    > $computername=$null,
    > [switch]$param1,
    > [switch]$param1,
    > [switch]$param1
    > )
    >
    >
    >
    > and the following scriptblock doesn't work because the dotsourcing is
    > not at the first line...
    >
    >
    > param(
    > $computername=$null,
    > [switch]$param1,
    > [switch]$param1,
    > [switch]$param1
    > )
    > . ./functions.ps1
    >
    >
    >
    >
    >
    > how should i do ???
    >
    > Bye
    > Nico
    >



      My System SpecsSystem Spec

  3. #3


    Kiron Guest

    Re: param VS dotsourcing

    Maybe Hecks' idea helps:
    news:0C87BFCA-4FE1-4654-AB9D-66B649A1A6F9@microsoft.com

    --
    Kiron

      My System SpecsSystem Spec

  4. #4


    Nicopilami Guest

    Re: param VS dotsourcing

    On 20 août, 17:02, "Brandon Shell" <tshell.m...@gmail.com> wrote:
    > Param must be at the begining and there is no requirement for DoT sourcing
    > that I know of.
    >
    > Your Second example worked for me except you had three [switch]$param1
    > instead of 1/2/3.
    >
    > param(
    > $ccomputername = $null,
    > [switch]$param1,
    > [switch]$param2,
    > [switch]$param3
    > )
    > . $pwd\bleh.ps1
    >
    > What is the problem you are having? Error?
    >
    > "Nicopilami" <n.chauss...@gmail.com> wrote in message
    >
    > news:1187621550.303710.233370@r34g2000hsd.googlegroups.com...
    >
    >
    >
    > > hello, i would like to use some fonctions of a dot-sourced file and
    > > get all the parameters setted in the command line at the same time;

    >
    > > how to make the following lines exist at the same time ?
    > > i've read that every dotsourced reference had to be located at the
    > > first line of the script, and the same things for the param command.

    >
    > > For this reason, the following scriptblock doesn't work because param
    > > isn't at the first line...

    >
    > > . ./functions.ps1
    > > param(
    > > $computername=$null,
    > > [switch]$param1,
    > > [switch]$param1,
    > > [switch]$param1
    > > )

    >
    > > and the following scriptblock doesn't work because the dotsourcing is
    > > not at the first line...

    >
    > > param(
    > > $computername=$null,
    > > [switch]$param1,
    > > [switch]$param1,
    > > [switch]$param1
    > > )
    > > . ./functions.ps1

    >
    > > how should i do ???

    >
    > > Bye
    > > Nico- Masquer le texte des messages précédents -

    >
    > - Afficher le texte des messages précédents -


    the dotsourced file contains a function, and when i call this function
    from the first script after i have dotsourced the file, nothing
    happens. :'(
    (three time of $param1 is a bit too much, actually, it was $param1, 2,
    3 ...but i forgot to change it when i changed and pasted the code
    here...)

    how could i do for making it work ?



      My System SpecsSystem Spec

  5. #5


    Brandon Shell Guest

    Re: param VS dotsourcing

    Im not sure what is not working for you. What is the function your calling
    suppose to do? Do you set $ErrorActionPreference anywhere?

    Here is my test... I have two scripts. Testdotsource.ps1 and bleh.ps1
    == testdotsource.ps1 ===
    param(
    $computername = $null,
    [switch]$param1,
    [switch]$param2,
    [switch]$param3
    )
    .. t:\pathtoscript\bleh.ps1

    foo1
    foo2
    foo3
    ===================
    ===== bleh.ps1 ========
    function foo1{"foo1 worked"}
    function foo2{"foo2 worked"}
    function foo3{"foo3 worked"}
    ====================

    122# T:\Scripts\testdotsource.ps1
    foo1 worked
    foo2 worked
    foo3 worked


    "Nicopilami" <n.chaussard@gmail.com> wrote in message
    news:1187630734.115009.195920@g4g2000hsf.googlegroups.com...
    On 20 août, 17:02, "Brandon Shell" <tshell.m...@gmail.com> wrote:
    > Param must be at the begining and there is no requirement for DoT sourcing
    > that I know of.
    >
    > Your Second example worked for me except you had three [switch]$param1
    > instead of 1/2/3.
    >
    > param(
    > $ccomputername = $null,
    > [switch]$param1,
    > [switch]$param2,
    > [switch]$param3
    > )
    > . $pwd\bleh.ps1
    >
    > What is the problem you are having? Error?
    >
    > "Nicopilami" <n.chauss...@gmail.com> wrote in message
    >
    > news:1187621550.303710.233370@r34g2000hsd.googlegroups.com...
    >
    >
    >
    > > hello, i would like to use some fonctions of a dot-sourced file and
    > > get all the parameters setted in the command line at the same time;

    >
    > > how to make the following lines exist at the same time ?
    > > i've read that every dotsourced reference had to be located at the
    > > first line of the script, and the same things for the param command.

    >
    > > For this reason, the following scriptblock doesn't work because param
    > > isn't at the first line...

    >
    > > . ./functions.ps1
    > > param(
    > > $computername=$null,
    > > [switch]$param1,
    > > [switch]$param1,
    > > [switch]$param1
    > > )

    >
    > > and the following scriptblock doesn't work because the dotsourcing is
    > > not at the first line...

    >
    > > param(
    > > $computername=$null,
    > > [switch]$param1,
    > > [switch]$param1,
    > > [switch]$param1
    > > )
    > > . ./functions.ps1

    >
    > > how should i do ???

    >
    > > Bye
    > > Nico- Masquer le texte des messages précédents -

    >
    > - Afficher le texte des messages précédents -


    the dotsourced file contains a function, and when i call this function
    from the first script after i have dotsourced the file, nothing happens. :'(
    (three time of $param1 is a bit too much, actually, it was $param1, 2,
    3 ...but i forgot to change it when i changed and pasted the code
    here...)

    how could i do for making it work ?



      My System SpecsSystem Spec

  6. #6


    Nicopilami Guest

    Re: param VS dotsourcing

    On 20 août, 19:11, "Kiron" <Ki...@HighPlainsDrifter.com> wrote:
    > Maybe Hecks' idea helps:news:0C87BFCA-4FE1-4654-AB9D-66B649A1A6F9@microsoft.com
    >
    > --
    > Kiron


    This link describes and resolve totally my problem !!!!
    thank you very much to Kiron for the link, and to Hecks for the
    solution !!!!!

    bye
    Nico


      My System SpecsSystem Spec

param VS dotsourcing problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Param - named vs positional? Gerry Hickman PowerShell 6 03 Feb 2010
PowerShell param array Daniel Jameson PowerShell 2 23 Aug 2008
Using param with InvokeReturnAsIs cashfoley PowerShell 9 18 Jan 2008
What expressions can you specify in the -filter param for dir Bob Landau PowerShell 2 28 Aug 2007
Invoke-Item with param. MiroslavK PowerShell 2 03 May 2007