I’m creating a script to handle moving a database and a file tree from a live server to a test server.
One of the things that needs to happen on the test server is for a number of services to be stopped in specific order before the running database is dumped and then restart them in reverse order.
My first thought was that I should just pop the service names in an array and run a foreach with Stop-Service. But I think I heard somewhere that you can’t be sure that POSH will run an array in the same order that you entered the items. Also I would have to reverse the order once I need to restart the services.
I’m aware that I can just do one line for each service but I’d really prefer to just have the service names in one location rather than in both the Stop-Service and Start-Service function.
Is a hash table a better idea for dealing with items in a specific order?
And what’s the best way of reversing the order for the Start-Service function?