troubleshooting Question

powershell variable inside quotes

Avatar of DevSupport
DevSupport asked on
5 Comments1 Solution480 ViewsLast Modified:
Hi Experts,

I am trying to get the value from a dropdown into the Invoke Command to Start a windows service in a remote system.

When I do write-host $dispname I get the value as "Some Service" but when I try to run the Invoke-Command I get the error below:

function Start-TC{
$dispname = $objAppDropDown.SelectedItem
write-host $dispname
Invoke-Command -Computername $objappsvrname.Text -ScriptBlock { Start-Service -DisplayName "$dispname"  }


With "$dispname" in quotes:

Cannot bind argument to parameter 'DisplayName' because it is an empty string.

Without quotes:
Cannot bind argument to parameter 'DisplayName' because it is null.

Full script attached
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 5 Comments.
Join the Community
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 5 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