Arguments not passing through

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: $server
Basically, 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"