So i have a powershell script im toying with that i'd like to ask the community's help. I have to preface that I am not always the best in communicating what I am attempting to do, partly because i dont have programming experience so please bear with me, and ask questions/correct me if i use incorrect words to explain what i mean.
With that said, Here's what I am trying to do:
while incrementing both services and startuptypes:
stop service A ($services) on server X ($rebootingServer)
Disable service A ($services) on server X ($rebootingServer)
Given: we know service A is disabled on server Y prior to script running
Enable service A on server Y based on text file list $startuptypes
- Start service A on server Y
- Rinse and repeat until $services and $startuptypes are at the end of each list
So assume $services has:
bits
appmgmt
and $startuptypes has:
Automatic
Manual
i want them to be applied respectively (bits > automatic appmgmt > manual)
Heres what i have thus far:
$services = Get-Content "C:\TEMP\services.txt"
$Startuptypes = Get-Content "C:\TEMP\StartupTypes.txt"
$RebootingServer = Read-Host 'Name of the server that you are bringing down'
$FailoverServer = Read-Host 'Name of the server it is failing over to'
#foreach ($service in $services && $Startuptype in $Startuptypes) {
Invoke-Command -ComputerName $RebootingServer -ArgumentList $service - ScriptBlock {param($service) Stop-Service $service}
Start-Sleep -s 3
Invoke-Command -ComputerName $RebootingServer -ArgumentList $service - ScriptBlock {param($service) set-service $service -StartupType Disabled}
Start-Sleep -s 10
Invoke-Command -ComputerName $FailoverServer -ArgumentList $service $StartupType -ScriptBlock {param($service,$startuptype) Set-Service $service -StartupType $startuptype}
Start-Sleep -s 3
Invoke-Command -ComputerName $FailoverServer -ArgumentList $service - ScriptBlock {param($service) Start-Service $service}
Start-sleep -s 10
}
The 'for each' statement is pseudo-code of what i want it to do, yet unsure if that exists or how to write it accordingly. I dont even know what that would be appropriately called. Multiple conditionals? That aside, how would i properly write what I am attempting to accomplish? Thank you for any help in advanced.