Arguments not passing through

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 5 months ago.

  • Author
    Posts
  • #6017

    by justjon at 2013-02-08 01:24:24

    Hi all,

    I'm brand new to PowerShell and am having many problems trying to get arguments to pass through succesfully.

    I'm using PowerGUI to compile the script into an exe.

    The part of the script that isn't working is this;

    param ( [string]$state, [string]$server )

    Write-Host State: $state Server: $serverBasically, when running the script it just shows:

    State: Server]
    I've tried various different things but simply can't get it to work.

    Any help would be appreciated.

    by Klaas at 2013-02-08 03:05:48

    So the Write-Host statement works, but both variables are empty.
    I think we need to see more of your script and the way you call it to find the problem.

    by pstosso at 2013-03-28 22:39:08

    try something like this.

    function test ( $state, $server){
    Write-Host "State: $state Server: $server"
    }

    test var1 var2

    my output was "State: var1 Server: var2"

    by nohandle at 2013-03-29 06:48:17

    a user uploaded image
    Seems to work OK for me if this is what you are after.

    If you'd save that script to c:\temp as test.ps1 you then need to call it (from another script) like this:
    c:\temp\test.ps1 -State "ok" -Server "localhost"

You must be logged in to reply to this topic.