I have a list of servers and they all have a folder called c:\auditLogs. I need to make sure there is never more than 1 file in that folder. I need to get the server name and a file count in the result set. It isn’t working.
Your script never actually runs commands remotely. To run a command/script on a remote machine you need to use something like Invoke-Command or a cmdlet with a -ComputerName parameter. Also, I see you are doing Get-Content on a .csv file. If this is truly a comma seperated value file, then you need to use Import-Csv and access the servername value by it’s header as the property. i.e.
To be more accurate you could also use cmdlets with CIMSession or PSSession to run remotely. Or just enter an interactive session with a single remote machine in ISE for example.
Also consider this approach doesn’t scale if one is doing a larger number of servers (pick the number). If this is the case, I would have the checking process run as a service on each of the servers rather than trying to do a one to many approach. Then have your one to many approach just validate that specific services are running on each server. If you have really really big environment, then multi-thread your one to many approach so you can check 20 servers or better concurrently.
Great point cadayton! Cmdlets like Invoke-Command will take a collection (array) as an argument for the -ComputerName parameter. When you do that, the scriptblock would be transmitted to all of the remote hosts identified to work in parallel and as the results come back a new property called PSComputerName will be added to the objects identifying where the results came from so no need to manually put the commputername in your script. If instead you call Invoke-Command or any other remoting command in a loop with each iteration containing only one remote host then it would be in serial and not very scalable.