Property cannot be found on a hashtable passed in from another script
I can't believe how difficult it is to find how to parse and use parameters passed in from another script! I've been at this for almost 5 hours.
There are plenty of articles on how to create a hashtable, and some on how to pass a hashtable to another script, but nothing on what to do with the hashtable once the target script receives it.
This is an excerpt from "Test 1A-sending script.ps1"
Here are the results of running the sending script, which appear in a separate window for the receiving script:
Made it to test 1B.System.Collections.HashtableThe property 'ComputerName' cannot be found on this object. Verify that the property exists.At: C:\Workshop\PowerShell-work\Passing arguments\Test 1B-receiving script.ps1:61 char:1+Write-Host $parms2.ComputerName -ForegroundColor Gray
Because there is no need to. The way I showed, called splatting, you supply a hash table containing parameters to other funtcions and cmdlets, with the keys as parameter name and the value as parameter value.
Your issue here is not how to read out the parameters in the called script, but how to provide them. A "$hashtable" almost always results in the type string (!) you see.
I didn't know what to set the parameter variable to. @() did the trick. I modified my receiving script and the hashtable values were extracted. Thank you very much!
Alan Varga
ASKER
The correct solution was simple and easy to understand, but I couldn't find this after hours of searching and reading. There is always an export at EE who can defuse my frustration. Thanks Ben!
VieleFragen, your statement in #a42111113 is wrong. The key was to provide the hash table as parameter when calling, instead of a string. Your way to call the second script was wrong.
Be aware that that code is correct for having a hash table as single parameter value, but not for passing true parameters thru calls. E.g., you could not do that for calling Get-WMIObject in the second script.
Open in new window