How to pass param value to the Invoke-Command cmdlet?
<p>I wrote a simple <a href="/questions/tagged/powershell" class="post-tag" title="show questions tagged &#39;powershell&#39;" rel="tag">powershell</a> script to modify hosts file on remote machines but something goes wrong.</p>

<p>Script:</p>

<pre><code>param(
   [string]$value
)

$username = 'username'
$password = 'password'
$hosts = "172.28.30.45","172.28.30.46"
$pass = ConvertTo-SecureString -AsPlainText $password -Force
$cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username,$pass

ForEach ($x in $hosts){
   echo "Write in $x , value: $value"
   Invoke-Command -ComputerName $x -ScriptBlock {Add-Content -Path "C:\Windows\system32\drivers\etc\hosts" -Value $value} -Credential $cred
   echo "Finish writing."
}

echo "End of PS script."
</code></pre>

<p>When run, it writes a new <strong>empty line</strong> for each hosts file. This line <code>echo "Write in $x , value: $value"</code> displays <strong>$value</strong> value.
What I'm doing wrong?</p>