Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, November 3, 2016 1:24 PM
I have a script that stop and disable two services and set the startuptype to disabled.
#Stop script
Get-Service Ag*| Stop-Service -PassThru | Set-Service -StartupType disabled
Get-Service World* | Stop-Service -PassThru | Set-Service -StartupType disabled
#Start script
Get-Service Ag* | Set-Service -StartupType automatic -passThru | Start-Service
Get-Service World* | Set-Service -StartupType automatic -passThru | Start-Service
Questions:
- How can I include a list of servernames to these scripts? So that these services are stopped on multiple servers at once.
a) If the servernames are included in a txt-file
b) If the servernames can be found with a sql query (sql express database)?
Thanks
All replies (2)
Thursday, November 3, 2016 5:29 PM ✅Answered
Here is one example of using a text file with Server Names in it.
$SrvNames = Get-Content -Path 'C:\*.txt'
foreach ($Server in $SrvNames)
{
Get-Service -Name Ag*, World* -ComputerName $Server | Stop-Service -PassThru | Set-Service -StartupType disabled
}
Thursday, November 3, 2016 4:45 PM
Start here: https://technet.microsoft.com/en-us/dd742419
\(ツ)_/