I am horribly stuck into a challenge for designing a powershell code to reboot a list of servers from a CSV depending on a Sequence Number.
DependentList.csv
CI,Sequence
serverA,1
serverB,3
serverC,5
ServerD,2
ServerE,2
ServerF,4
ServerG,1
This is how the CSV looks like with Server Name and its Sequence to be rebooted.
Note:
Servers with same sequence number should be rebooted at a time together followed by a delay and then the Next sequence server to be rebooted.
Ex, ServerA & ServerG are with same sequence number ‘1’ hence to be rebooted together and then ServerD & ServerE since its sequence number is 2…followed by 3 and 4 and 5…
I am seeking for suggestions on how shall I proceed or any bits or piece of code that would help me…
Hi,
Restart-Computer is the Cmdlet which will restart the computers, the paramater -ComputerName
accepts multiple computer names at a time.
you can use this as simple as you can like.
You can run it through the console as
Restart-Computer -Computername ServerA.xyz.com, ServerB.xyz.com. [or]
Restart-Computer -Computername ServerA, ServerB.
you can save this as a script also such as with name RestartSeq1.ps1
you can also pick server names from a csv. [have seperate sequence server names in seperate CSV’s]
Import-CSV -Path D:\Names.csv | Restart-Computer
if you have Server names in a text file with one name per line.
Get-Content -Path D:\Names.txt | Restart-Computer
you can learn more on this by typing in the powershell console.
The generic *-Object cmdlets are, IMO, one of the main reasons to start using PowerShell in the first place. With the object-based pipeline and this built-in query language that you can apply to anything, you can do some really impressive things with very few lines of code. I think Group-Object and Sort-Object get overlooked quite a bit.