SharePoint Entwicklungsfarm hoch- und runterfahren
Ich war gerade nochmal “kreativ” und habe mir ein Skript gebaut, mit dem ich meine Hyper-V Maschinen für die SharePoint Farm zuhause hoch- und runterfahren kann.
Es beachtet die korrekte Reihenfolge. Erst geht die Basis rauf – also das AD und in meinem Fall der Router zum Netz, danach der SQL und dann die SharePoint VMs.
Das möchte ich euch natürlich nicht vorenthalten. Bitte ersetzt die Maschinen-Namen einfach durch eure eigenen Namen.
Die 10 Sekunden Wartezeit nach dem Start eines Blocks solltet ihr ggf. auch an eure Umgebung anpassen (bei manchen wird ein Start vielleicht länger dauern, andere hatten mehr Geld für ihre Workstation/Server als ich 😉 )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Change VM names to your own names | |
$baseVMs = @("ROUTER","AD") | |
$sqlVMs = @("SPSQL2016") | |
$sharepointVMs = @("SP2016-1","SP2016-2") | |
# ————————————————————————————————- | |
function Start-VMSet($vmSet){ | |
$vmStarted = $false | |
$waitTime = 10 | |
foreach ($vmName in $vmSet) { | |
$vm = Get-VM -Name $vmName | |
write-host $vm.Name ": " -NoNewline | |
switch ($vm.State) { | |
"Running" { write-host "already running" -f Green } | |
"Off" { | |
write-host "starting" -f Cyan | |
Start-VM -VM $vm | |
$vmStarted = $true | |
} | |
default { write-host "unknown state:" $vm.State -f Yellow } | |
} | |
} | |
if ($vmStarted) { | |
write-host "Waiting for" $waitTime "seconds for machines to boot up…" | |
Start-Sleep -Seconds $waitTime | |
} | |
} | |
function Stop-VMSet($vmSet){ | |
foreach ($vmName in $vmSet) { | |
$vm = Get-VM -Name $vmName | |
write-host $vm.Name ": " -NoNewline | |
switch ($vm.State) { | |
"Off" { write-host "already stopped" -f Green } | |
"Running" { | |
write-host "stopping" -f Cyan | |
Stop-VM -VM $vm | |
} | |
default { write-host "unknown state:" $vm.State -f Yellow } | |
} | |
} | |
} | |
write-host "1….: Start VMs`n2….: Stop VMs" | |
$command = Read-Host "Well?" | |
if ($command -eq 2 -and (Get-VM | ? { $_.State -eq "Running" }).Count -eq 0) { | |
write-host "Funny 🙂 – There is no VM running. Did you mean start?" -f Yellow | |
exit | |
} | |
switch ($command) { | |
1 { # Start | |
write-host "Starting base VMs…" -f Magenta | |
Start-VMSet $baseVMs | |
write-host "Starting SQL VMs…" -f Magenta | |
Start-VMSet $sqlVMs | |
write-host "Starting SharePoint VMs…" -f Magenta | |
Start-VMSet $sharepointVMs | |
} | |
2 { # Stop | |
$withBaseVMs = Read-Host "Also stop base VMs? [y/N]" | |
write-host "Stopping SharePoint VMs…" -f Magenta | |
Stop-VMSet $sharepointVMs | |
write-host "Stopping SQL VMs…" -f Magenta | |
Stop-VMSet $sqlVMs | |
if ($withBaseVMs.ToLower() -eq "y") { | |
write-host "Stopping base VMs…" -f Magenta | |
Stop-VMSet $baseVMs | |
} else { | |
write-host "Skipped base VMs" -f Magenta | |
} | |
} | |
default { exit } | |
} | |
write-host "finished" -f Green |