We help IT Professionals succeed at work.
Get Started

Property cannot be found on a hashtable passed in from another script

Alan Varga
Alan Varga asked
on
408 Views
Last Modified: 2017-04-27
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"
$parms = @{
    ComputerName = 'mike';
    ComputerId = 'SYS 001'
}

#Display hashtable
$parms.Keys
$parms.Values

$filePath = ".\Test 1B-receiving script.ps1"
$commandLine = "-NoExit & `'$filePath`' $parms"
Write-Host `n$commandLine -f Cyan

Start-Process Powershell.exe -ArgumentList $commandLine

Open in new window


and this is an excerpt from "Test 1B-receiving script.ps1"
Param(
    $parms2
)

Write-Host "Made it to test 1B."
Write-Host $parms2 -ForegroundColor Yellow
Write-Host $parms2.ComputerName -ForegroundColor Gray

Open in new window


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.Hashtable
The 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

Open in new window

Comment
Watch Question
Lead SaaS Infrastructure Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE