DevSupport
asked on
powershell variable inside quotes
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.SelectedIt em
write-host $dispname
Invoke-Command -Computername $objappsvrname.Text -ScriptBlock { Start-Service -DisplayName "$dispname" }
}
Error:
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
scr-1.txt
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.SelectedIt
write-host $dispname
Invoke-Command -Computername $objappsvrname.Text -ScriptBlock { Start-Service -DisplayName "$dispname" }
}
Error:
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
scr-1.txt
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank You so much!
ASKER
Also can we send a script file to be executed in a remote system through scriptblock?
Please let me know.
Thank You!
DevSupport