Message from STDIN is empty. Why?

Welcome Forums General PowerShell Q&A Message from STDIN is empty. Why?

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
3 years, 4 months ago.

  • Author
    Posts
  • #30474

    Participant
    Points: 0
    Rank: Member

    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.

  • #30478

    Participant
    Points: 0
    Rank: Member

    HI,

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

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

    Check : https://technet.microsoft.com/en-us/library/hh847893.aspx

    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

  • #30479

    Member
    Points: 0
    Rank: Member

    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.

  • #30485

    Participant
    Points: 0
    Rank: Member

    Thanks, guys! Your both answers are helped me.

The topic ‘Message from STDIN is empty. Why?’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort