Help with powershell script RRS feed

  • Question

  • I keep getting no results when trying to execute this code:


    $command = "Get-WindowsFeature | where-object {$_.Name -eq $Feature }"

    $command = [scriptblock]::Create($command)

    $remoteFeature = Invoke-Command -ComputerName $ServerIP -ScriptBlock $command -Credential $credentialsServer 

    write-host $remoteFeature

    I've tried everything I can think of, all variations of quotes around $Feature, but I just get no results when executing remotely.  Locally on the server it executes fine, it's only when I try to execute remotely that I can't get this to work.  I'm trying to verify that the feature which will be installed is a valid feature.

    • Moved by Baron Bi Thursday, September 6, 2018 2:34 AM
    Monday, August 27, 2018 8:31 PM

All replies

  • Here's a typical response:

    The term '.Name' is not recognized as the name of a cmdlet, function, script 
    file, or operable program. Check the spelling of the name, or if a path was 
    included, verify that the path is correct and try again.
        + CategoryInfo          : ObjectNotFound: (.Name:String) [], CommandNotFou 
        + FullyQualifiedErrorId : CommandNotFoundException
        + PSComputerName        :

    Monday, August 27, 2018 8:34 PM
  • Hi,

    thanks for posting here.

    This forum is about desktop application development. For your case which is more related to PowerShell commands, I suggest you post on this forum below.


    Your understanding and cooperation will be grateful.

    Best Regards,

    Baron Bi

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, August 28, 2018 1:25 AM
  • Another useful forum for Powershell is The Scripting Guy.

    Use single quotes instead of double so the $ chars are preserved in the variable:

    $command = 'Get-WindowsFeature | where-object {$_.Name -eq $Feature }'



    • Edited by Pavel A Tuesday, August 28, 2018 11:30 AM
    Tuesday, August 28, 2018 11:15 AM