Welcome.
It’s all well a good to be new, but you at least need to show us your work. We are more than happy to help you with your code, but in virtually all these types ‘Q & A’ forums, folks will tell you that the members or the site is not a free code writing service. So, just a heads up when make these sorts of requests.
Never ever run anyone’s code, regardless of where you get it from if you do not fully understand what it is doing. You could damage your systems, network, organization, etc., which in turn would have very negative implications for you.
This is all mostly basic PS stuff and taking a quick online video course via Microsoft Virtual Academy or even YouTube will give you all you need. On this site, there are lots of free eBooks, videos for you to use. Free Resources – PowerShell.org. You really need to do this to limit confusion and frustration you are going to encounter as a new PS type.
Since you are saying you are trying to do this to remote computers, this means PowerShell Remoting needs to be properly setup. It also means you need to be an administrator on the target computers for a lot of what PS does or specifically configure PS to allow a non-admin to do this.
You can physically type each of your question points in your favorite search engine and get a ton of samples of how to do each step, then just put it together.
Heck, even looking at the help files for the specific cmdlets to use has several examples on how to do these kinds steps. read the help files, practice with the examples, read the help files again.
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/?view=powershell-5.1
All-in-all, you are asking for more than what you are showing here:
<li>How to read file content using a loop</li>
<li>How to use PSRemoting</li>
<li>How to set execution policies for scripting</li>
<li>How to use Remove variable</li>
<li>How to stop/start a process or service</li>
<li>How to copy / remove / replace files on computers.</li>
<li>How to run scripts without impact - Using the -WhatIf switch.</li>
1. Pull computer names from a .txt and loop through them
Depending on what you .txt looks like, which you do not show, so forces us to guess, you have two cmdlets to look toward.
Get-Help -Name Get-Content -Examples
Get-Help -Name Import-Csv -Examples
2. Stop a service on each computer
Get-Help -Name Invoke-Command -Examples
Get-Help -Name Stop-Service -Examples
I am note a Palo Alto SME - but this does not look like a service to me, but a .exe process that is running that you are trying to control.
I did a quick lookup of this command and it’s an exe. So the question your are asking is not quite valid for the step you are asking for.
https://www.paloaltonetworks.com/documentation/41/endpoint/endpoint-admin-guide/troubleshooting/cytool/access-cytool
So, this means …
https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx
cd c:\Program Files\Palo Alto Networks\Traps
cytool runtime stop
So, that means this is a process you are trying to stop and start.
Get-Help Get-ExecutionPolicy -Examples
Get-Help Set-ExecutionPolicy -Examples
Get-Help -Name Enable-PSRemoting -Examples
Get-Help -Name Invoke-Command -Examples
Get-Help -Name Stop-Process -Examples
Get-Help -Name Start-Process -Examples
3. Replace a file on the destination computer with a different verstion
Get-Help -Name Remove-Item -Examples
Get-Help -Name Copy-Item -Examples
4. Start the service
Get-Help -Name Start-Service -Examples
Continue on down through the list of computers.
about_Loops
https://social.technet.microsoft.com/wiki/contents/articles/4542.powershell-loops.aspx
# Short rough example - using -WhatIf to prevent any real changes / actions and verbose to report on what is happening.
$ComputerList = (Get-Content -Path 'd:\Temp\computerlist.txt')
ForEach ($LineItem in $ComputerList)
{
"Processing - $LineItem"
Invoke-Command - ComputerName $LineItem -ScriptBlock {
Stop-Process-Name 'cytool' -WhatIf -Verbose
Copy-Item 'Some file fullpath' -Destination 'FullDestination' -WhatIf -Verbose
Start-Process-Name 'C:\Program Files\Palo Alto Networks\Traps\cytool.exe' -Arguments 'whatever .exe arguments are needed' -WhatIf -Verbose
}
}
# If this was truly a service
ForEach ($LineItem in $ComputerList)
{
"Processing - $LineItem"
Invoke-Command - ComputerName $LineItem -ScriptBlock {
Stop-Service-Name 'cytool' -WhatIf -Verbose
Copy-Item 'Some file fullpath' -Destination 'FullDestination' -WhatIf -Verbose
Start-Service-Name 'cytool' -WhatIf -Verbose
}
}