Trying to run Powershell Advance Function on a List of machines.

I have a Powershell script/function that works when you run in locally on one device. I have a need to run it on multiple devices from a csv or txt file. How can I do that? It is a pretty complexed script with over 3500 lines in it so I need to ensure that everything in the script gets executed on each of the devices in the list. I am happy to share the script if that would be helpful.

Any insight or examples of how this could be accomplished is greatly appreciated.

I would recommend Invoke-Command. PS has great documentation on it Get-Help Invoke-Command You can use it to run an entire script on multiple remote computers. For example:

$computerlist = Get-Content "C:\lists.txt"

Invoke-Command -ComputerName $computerlist -FilePath "C:\myscript.ps1"

By default any objects returned from Invoke-Command will include a PSComputerName property which will by the computername of the remote machine it came from. This is necessary because the script will be running simultaneously on machines you pass to the ComputerName parameter. In my example $computerlist.

Anyway, that is where I would start. Good luck and post back if you need any further help.