by justjon at 2013-02-08 01:24:24
Hi all,by Klaas at 2013-02-08 03:05:48
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 )
Basically, when running the script it just shows:
Write-Host State: $state Server: $server
State: Server]
I’ve tried various different things but simply can’t get it to work.
Any help would be appreciated.
So the Write-Host statement works, but both variables are empty.by pstosso at 2013-03-28 22:39:08
I think we need to see more of your script and the way you call it to find the problem.
try something like this.by nohandle at 2013-03-29 06:48:17function test ( $state, $server){
Write-Host "State: $state Server: $server"
}
test var1 var2
my output was "State: var1 Server: var2"
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"