I have a custom CMDlet that can query the status of each service for the CSV-list of computers and then CVS- The file is okay, see the example below. I want to choose this CSV-output (this pipe is really true) and then run the comparison; Pure array query For example, calculate the number of unique computers and list every service list that runs on all computers, or the services running on all those services do not have to run
I have used several tests I went through the medium and although I can read the array input, select the specific kernel, I can not list the selection of unique computers and count them. Below is the current version of my code, where it declines in the list of computer names and shows me the proper calculations of unique values and / or 3.
In this example, the services running on each computer should be the result of:
SVc1
Where am I wrong in my thinking? Your cooperation is commendable. Although not new to programming, I PS
function myTest {[cmdletBinding ()] absolute ([parameter (mandatory = $ true, valueFromPipeline = $ True, ValueFromPipelineByPropertyName = $ True, HelpMessage = "List of input CSV files, ComputerName, Service, State")] [array] $ listofficesandscs) BEGIN {} Process {{$ # $ listofferingSVCS = $ listOffsourceAndSVCs | Where {$ _. State - AQ is "running"} | | Select ComputerName, ServiceName # write-output $ ListOfRunningSvcs $ UniqComps = $ ListOfSvrsAndSvcs | Group {$ _. ComputerName} | Write ComputerName output, select $ Unique Comps} {write-warning $ _. exception. Message} end {}} END {}} import-csv \ ComputerServicesList.csv | MyTest | Ft
My input CSV looks like this: COMPName SvcName state localhost running SVC 1 localhost Svc2 turned off Comp1 running SVC1 running Comp1 Svc2 Comp1 running Svc3 Comp2 Running Svc1 running Comp2 Svc3 < / Pre>
import-CSV
returns an array so the custom function No need Piping directly group-object
requires a response from you.
$ data = import-csv \ ComputerServicesList.csv $ uniqueComputerCount = ($ data | order-object CompName-exclusive). Data $ data | Group-object svcname | Where-object {$ _. Calculation -q $ uniqueComputerCount} | Select - Expand Advertisement Name
This will return all the services present on all the hosts. In which case only the SVC1
is. If you want to make sure that they were running then the same output would be pure with small changes
$ data | Group-object svcname, state | Where-object {$ _. Calculation -q $ uniqueComputerCount} | Selection-object-expandedparty name. The e-object {($ _ -split ",") [0]}
is more to come from this, but I have the component for the question Are you expecting to process each line and compare some matching variables like you go with? PowerShell basically handles it when it looks like a garbage.
At present your function is getting a line of data at one time and that single item is being sent to group-object
as I have in my comments It was said that you must match your variables to CompName
ComputerName
No comments:
Post a Comment