Need an assist with accepting pipeline input

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Adam Bertram Adam Bertram 1 year, 11 months ago.

  • Author
    Posts
  • #21324
    Profile photo of Adam Bertram
    Adam Bertram
    Participant

    I've created a function to read some WMI objects and a function to set a property on one of the attributes of each object returned from this function. All functions work properly without pipeline input but I want to change that.

    The output of the "Get" function looks like this:

    http://screencast.com/t/C5BVdnEiHr

    I've created a function that looks like this:

    http://screencast.com/t/Q2Vs6qkZgI

    I'm assuming if I've got the $InputObject param object type set correctly then the params for the Disable function will be bound to the $InputObject by value. However, I'm consistently getting the error like it's not. I'm trying to use data from a CSV that works if I just use each row of the CSV into the Get cmdlet but whenever I try to pipe that to the Disable cmdlet I get the below error.

    http://screencast.com/t/HCyu37kuQ

  • #21325
    Profile photo of Don Jones
    Don Jones
    Keymaster

    The WMI objects are a little janky because of the ETS stuff PowerShell does. Try casting $InputObject without a type, or just as [object] and see if that works.

  • #21328
    Profile photo of Adam Bertram
    Adam Bertram
    Participant

    It looks like it bound to my custom function but now since it was cast to a generic object Set-WmiInstance doesn't like it since it's looking for a management object.

  • #21329
    Profile photo of Adam Bertram
    Adam Bertram
    Participant

    I finally figured it out. I originally wanted to exclude all the properties that started with "__" in my Get cmdlet so I was using Select-Object to do that. It was outputting the objects as Selected.System.Management.ManagementObject rather than System.Management.ManagementObject. As soon as I removed that Select-Object from the end and just allowed the default object to come from Get-WmiObject it worked like a champ.

You must be logged in to reply to this topic.