Thursday, 15 May 2014

PowerShell: Pipe contents of csv file in to custom function -


I have a custom PowerShell function that needs to accept the array of data coming from the CSV file (preferably another CMDlet which produces this CSV), read the material and then produce some desirable production based on a comparison. The comparative part works in the desired form, but only when I hardcode the import-CSV computer services list line inside the function. For flexibility, I should accept function OT as a parameter. Below is my current motto. I am out of the ideas on what to try at this point

Prefix

My input CSV looks like this:

 ComputerName ServiceName state localhost running SVC 1 localhost Svc2 turned off Comp1 running Svc1 running Comp1 Svc2 running Comp1 Svc3 Running Comp2's SVC1 running Comp2 SVC3 

Is this your previous question Looking For?

  I end up {$ uniqueComputerCount = ($ input | sort-object computer name-unic) - Host "Unique computer: $ uniqueComputerCount" $ input | Group-object service. Where-object {$ _. Calculation -q $ uniqueComputerCount} | Select- Expanded name *}  

then call:

  import-csv c: \ temp \ data.log | MyTest  

$ input has a complete pipeline unit so that it can be processed once per one line. Looks like you need PowerShell 3.0 to work for it. You can see to read more on this topic.

The explanation of the argument comes from my answer. Once we understand which question is better then I can merge both of them and remove one of them because it really looks like a duplicate.


No comments:

Post a Comment