Windows Vista Forums

Passing Parameters to Ps1 files

  1. #1


    james Guest

    Passing Parameters to Ps1 files

    Hi ,
    I have 2 questions in powershell



    1) I used to call visual studio command prompt in a btach file with
    following command :
    "call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86

    How to do this in .ps1 file.

    2) In batch files , to call another batch file with paramters , i used the
    following command:
    call "File1.bat" %Name% %Appn% %no%
    now if i have to call "File1.ps1" with same paramters what is the syntax




      My System SpecsSystem Spec

  2. #2


    Thomas Lee Guest

    Re: Passing Parameters to Ps1 files

    In message <6A2B625C-5373-43BF-87C7-3B428721929D@newsgroup>, james
    <james@newsgroup> writes

    >Hi ,
    >I have 2 questions in powershell
    >
    >1) I used to call visual studio command prompt in a btach file with
    >following command :
    >"call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
    >
    >How to do this in .ps1 file.
    & "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86

    >2) In batch files , to call another batch file with paramters , i used the
    >following command:
    >call "File1.bat" %Name% %Appn% %no%
    >now if i have to call "File1.ps1" with same paramters what is the syntax
    & "File1.bat" $Name $Appn $false

    But you need to create the variables $name and $Appn.

    Hope this helps. If you are still stuck, post the script you have so far
    and the scripting gods that inhabit this place will flock to your aid!

    Thomas



    --
    Thomas Lee
    doctordns@newsgroup

      My System SpecsSystem Spec

  3. #3


    Bob Landau Guest

    Re: Passing Parameters to Ps1 files

    There is a HUGE difference when calling a batchfile that sets up environment
    variables in Powershell vs the native NT shell.

    (which is what vcvarsall.bat is doing)

    What Thomas has stated below is true and does answer you question. But to
    get the results I believe you have more work. In a nutshell you need to

    1) Run the batchfile
    2) Call SET
    3) Pipe this to the Powershell envirnment
    4) Extract these and create the environment variables

    Here is an example that Bruce Payette has shown in his book. I'm hoping I
    don't get into too much trouble by posting it.

    The reasons why Powershell can't do what CMD is doing has to do with scoping
    rules also explained in his book. While I wouldn't want Powershell to have
    the same rules as the NT shell I do wish they worked better with existing
    batchfiles AND provided a cmdlet that did what the below does as well as
    allow you to pass parameters into it.

    function Get-BatchFile ($file)
    {
    $cmd = "`"$file`" & set"
    cmd /c $cmd | Foreach-Object {
    $p,$v = $_.split('=')
    Set-Item -path env:$p -value $v
    }
    }

    If you really need to pass in parameters to this it takes a little more work
    but you should understand this well first.


    "Thomas Lee" wrote:

    > In message <6A2B625C-5373-43BF-87C7-3B428721929D@newsgroup>, james
    > <james@newsgroup> writes

    > >Hi ,
    > >I have 2 questions in powershell
    > >
    > >1) I used to call visual studio command prompt in a btach file with
    > >following command :
    > >"call "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
    > >
    > >How to do this in .ps1 file.
    >
    > & "C:\Program Files\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
    >

    > >2) In batch files , to call another batch file with paramters , i used the
    > >following command:
    > >call "File1.bat" %Name% %Appn% %no%
    > >now if i have to call "File1.ps1" with same paramters what is the syntax
    >
    > & "File1.bat" $Name $Appn $false
    >
    > But you need to create the variables $name and $Appn.
    >
    > Hope this helps. If you are still stuck, post the script you have so far
    > and the scripting gods that inhabit this place will flock to your aid!
    >
    > Thomas
    >
    >
    >
    > --
    > Thomas Lee
    > doctordns@newsgroup
    > .
    >

      My System SpecsSystem Spec

Passing Parameters to Ps1 files

Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing Parameters Between Subroutines John Quinn VB Script 2 23 Apr 2010
Passing parameters to a PS script Dan PowerShell 11 11 Nov 2009
passing [switch] parameters Jeff PowerShell 4 28 Jul 2007
Help with foreach-object and passing parameters Xanbar PowerShell 1 15 Nov 2006
passing parameters to script (ps1) IT Staff PowerShell 1 19 Oct 2006