troubleshooting Question

How do I pass a 2-part parameter from one PS script to another?

Avatar of Alan Varga
Alan VargaFlag for United States of America asked on
Powershell
7 Comments1 Solution93 ViewsLast Modified:
Given that I have defined these variables in Switchboard-network adapters.ps1

[string] $PsFolder = "C:\Computer\Hardware\Network adapters"
[string] $ScriptToRun = "$PsFolder\EnableDisableNetworkAdapters.ps1"
[string] $ParmToUse = "-wired query"

Open in new window


and my parameter declaration is at the top of EnableDisableNetworkAdapters.ps1

Param(
      [string] $wireless,
      [string] $wired,
      [switch] $help
      )

Open in new window


why does this work from the console command line

&'C:\Computer\Hardware\Network adapters\EnableDisableNetworkAdapters.ps1' -wired query

Open in new window


but neither of these work from within Switchboard-network adapters.ps1?

&"$ScriptToRun" "$ParmToUse"

&($ScriptToRun) ($ParmToUse)

Open in new window


My error trapping in EnableDisableNetworkAdapters.ps1 produces

[-wired query] is an unrecognized parameter.

Open in new window

ASKER CERTIFIED SOLUTION
Chris Dent
PowerShell Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Top Expert 2010

The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.

Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros