Message from STDIN is empty. Why?

Greetings! I cann’t understand why next code doens’t work:
import-module activedirectory

$message = Read-Host “Type your message”
icm -ComputerName (Get-ADComputer -filter “Name -like ‘w*’ -or Name -like ‘n*’” -searchbase “OU=422,OU=Depy1,OU=HQ,DC=contoso,DC=com”).Name -ScriptBlock {msg * “$($message)”}

And ISE says, that’s a message from STDIN is empty. I cann’t understand why. I have tried “$($message)”, $($message) and even just $message and nothing. Please help.


 -ScriptBlock {msg * "$($message)"}  

$message his unkown because you are in a script block.

Check :

ex :

C:\PS> invoke-command -scriptblock {param ($uu = "Parameter"); 
              "$uu assigned."} -args "Other value"

As always this is “A” way not “The” way of doing it

If you’re using PowerShell v3.0 or later, you can just put $using:message in your script block, which is more convenient. For PSv2 compatibility, you have to use the -ArgumentList parameter of Invoke-Command, as Cyril mentioned.

Thanks, guys! Your both answers are helped me.