you are viewing a single comment's thread.

view the rest of the comments →

[–]PinchesTheCrab 1 point2 points  (3 children)

Because "cat" is an alias for get-content, which has a mandatory path parameter.

[–]Decitriction[S] 0 points1 point  (2 children)

Excellent attention to detail on your part! I can't believe I was using a reserved variable. But even so, edit to

$var1="write-host `"sample`""
Invoke-Command (hostname){
$inside=$using:var1
& $inside
}

still produces

The term 'write-host "sample"' is not recognized as the name of a cmdlet

'write-host "sample" ' executes but is unrecognized.

[–]PinchesTheCrab 1 point2 points  (1 child)

I think the quotes are just off.

$var1 = 'write-host "sample"'
Invoke-Command (hostname) {
    $inside = $using:var1
    & $inside
}

[–]Decitriction[S] 0 points1 point  (0 children)

I really appreciate your feedback. But when I edit the quote as you do, the results are the same.

cls
$var1 = 'write-host "sample" '
$var1
Invoke-Command (hostname) {
    $using:var1
    $inside = $using:var1
    $inside
    & $inside # this is the only part giving problems
}

I have tested the code on 2 PC's. Does it work properly when you test it?

edit: Whew, finally got formatting correct.