I’m trying to write a script to check how long it’s been since a process was started on a group of 20ish remote machines. I can get the script to output the date correctly, but I’m stuck trying to get it to also tell me the name of the machine that corresponds to the date.
Here’s what I have so far:
$ErrorActionPreference = “silentlycontinue”
$computers = Get-Content -path C:\users\mprill\desktop\scripts\dispatchWorkstations.txt # Loads the computers variable with the machines listed in the text file
$output = foreach ($computer in $computers)
write-host Checking $computer
$DateFix = Get-WmiObject -class win32_process -ComputerName $computer | where name -eq ‘BrokerService.exe’ | select pscomputername,creationdate
$output | select pscomputername,date | export-csv -path c:\users\mprill\desktop\scripts\dispatchWorkstationBrokerRestartTime.csv
You can see I’ve tried adding in pscomputername in a couple spots to try to find out where I’m missing it, but all it does it output a column of dates into the .csv.
Can anyone please tell me what I’m missing or point me in a direction?