Need an assist with accepting pipeline input

This topic contains 3 replies, has 2 voices, and was last updated by  Adam Bertram 3 years, 7 months ago.

  • Author
  • #21324

    Adam Bertram

    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:

    I've created a function that looks like this:

    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.

  • #21325

    Don Jones

    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

    Adam Bertram

    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

    Adam Bertram

    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.