# Reboot Dependent Servers in sequence Powershell

**URL:** <https://forums.powershell.org/t/reboot-dependent-servers-in-sequence-powershell/3564>\
**Category:** PowerShell Help\
**Created:** [December 23, 2014, 7:10pm UTC](https://forums.powershell.org/t/reboot-dependent-servers-in-sequence-powershell/3564 "2014-12-23T19:10:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![karunanidhi-mishra](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@karunanidhi-mishra](https://forums.powershell.org/u/karunanidhi-mishra)\
**Post date:** [December 23, 2014, 7:10pm UTC](https://forums.powershell.org/t/reboot-dependent-servers-in-sequence-powershell/3564/1 "2014-12-23T19:10:33Z")

</div>

Hello Everyone,

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…

Thanks in Advance \_/\_

---

<div class="post-metadata">

**Author:** ![sikander-mirza](https://avatars.discourse-cdn.com/v4/letter/s/f05b48/32.png) [@sikander-mirza](https://forums.powershell.org/u/sikander-mirza)\
**Post date:** [December 23, 2014, 8:57pm UTC](https://forums.powershell.org/t/reboot-dependent-servers-in-sequence-powershell/3564/2 "2014-12-23T20:57:36Z")

</div>

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.

1. You can run it through the console as  
Restart-Computer -Computername [ServerA.xyz.com](http://ServerA.xyz.com), [ServerB.xyz.com](http://ServerB.xyz.com). [or]  
Restart-Computer -Computername ServerA, ServerB.  
you can save this as a script also such as with name RestartSeq1.ps1

2. 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

3. 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.

PS:&gt;help Restart-Computer -Full  
PS:&gt;Get-Command Restart-Computer -Syntax

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [December 23, 2014, 10:49pm UTC](https://forums.powershell.org/t/reboot-dependent-servers-in-sequence-powershell/3564/3 "2014-12-23T22:49:37Z")

</div>

Looks like you want a combination of Import-Csv, Group-Object, Sort-Object, and Restart-Computer. Something along these lines:

```
$data = Import-Csv DependentList.csv

$sequenceGroups = $data | Group-Object -Property Sequence

$sorted = $sequenceGroups | Sort-Object -Property { [int] $_.Name }

foreach ($sequenceGroup in $sorted)
{
    $computerNames = $sequenceGroup.Group | Select-Object -ExpandProperty CI
    Restart-Computer -ComputerName $computerNames -Wait
}
```

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:46pm UTC](https://forums.powershell.org/t/reboot-dependent-servers-in-sequence-powershell/3564/4 "2024-05-16T20:46:38Z")

</div>


