I am trying to update my .bat script to restart a service on many machines by putting the name of each machine in a notepad. For this I am trying to run a powershell script from cmd, but I can't get it to work. I have read that using ";" you can make a script in a single line but it doesn't work for me.
I'm trying to put this powershell code:
$FicheroEquipos = Get-Content -Path 'C:\Users\Cloudpg\Desktop\Morralla\test\equipos.txt'
ForEach ($Variable in $FicheroEquipos){
Get-Service -Name $Variable | Restart-Service -Verbose
}
like this in my .bat
start powershell.exe "$FicheroEquipos = Get-Content -Path 'C:\Users\Cloudpg\Desktop\Morralla\test\equipos.txt';ForEach ($Variable in $FicheroEquipos){Get-Service -Name $Variable | Restart-Service -Verbose}"
If anyone has an idea how to achieve my goal I would appreciate the help. Thank you very much. (For the code that I have put, the variable is for the services since I cannot currently carry out the tests on several computers.)