Last active
January 18, 2018 12:39
-
-
Save gitfvb/9d2272d6a4ee21b6c867d9cabe81a9d2 to your computer and use it in GitHub Desktop.
profitbricks handling through CLI / Powershell with interactive powershell tables for start/stop/remotedesktop
This file contains hidden or 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
| # create empty array for all server network interfaces | |
| $server=@() | |
| # run through every datacenter and append every single server to a list | |
| ( profitbricks datacenter list --json | ConvertFrom-JSON ) | ForEach { | |
| # append data from the datacenter | |
| $dataCenterId = $_.Id | |
| $dataCenterName = $_.Name | |
| $dataCenterLocation = $_.Location | |
| ( profitbricks server list --datacenterid $dataCenterId --json | ConvertFrom-JSON ) | ForEach { | |
| # append data from server | |
| $serverState = $_.State | |
| $serverCores = $_.Cores | |
| $serverMemory = $_.Memory | |
| $serverName = $_.Name | |
| $serverId = $_.Id | |
| $serverAvailabilityZone = $_.AvailabilityZone | |
| # get every IP from NIC | |
| ( profitbricks nic list --datacenterid $dataCenterId --serverid $serverId --json | ConvertFrom-JSON ) | ForEach { | |
| $_ | Add-Member -Type NoteProperty -Name "DCID" -Value $dataCenterId | |
| $_ | Add-Member -Type NoteProperty -Name "DCName" -Value $dataCenterName | |
| $_ | Add-Member -Type NoteProperty -Name "DCLocation" -Value $dataCenterLocation | |
| $_ | Add-Member -Type NoteProperty -Name "ServerState" -Value $serverState | |
| $_ | Add-Member -Type NoteProperty -Name "Cores" -Value $serverCores | |
| $_ | Add-Member -Type NoteProperty -Name "Memory" -Value $serverMemory | |
| $_ | Add-Member -Type NoteProperty -Name "ServerName" -Value $serverName | |
| $_ | Add-Member -Type NoteProperty -Name "ServerId" -Value $serverId | |
| $_ | Add-Member -Type NoteProperty -Name "AvailabilityZone" -Value $serverAvailabilityZone | |
| # show current object | |
| $_ | |
| # add server nic to list | |
| $server += $_ | |
| } | |
| } | |
| # show results of the last call | |
| #$dcserver | |
| } | |
| # show result in a nice formatted table popup | |
| $server | Sort -Property State | Select ServerState, Cores, Memory, ServerName, DCName, ServerId, DCID, DCLocation, AvailabilityZone, Lan, @{Name="IP";Expression={ $_.Ips }} | Out-GridView -PassThru | ForEach { mstsc /v:$($_.IP) } | |
| # Wait until key pressed | |
| Write-Host "Press any key to continue ..." | |
| $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") |
This file contains hidden or 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
| # show all datacenter | |
| profitbricks datacenter list | ConvertFrom-JSON | Format-Table | |
| # handle response data as powershell objects | |
| profitbricks server list --datacenterid <dcid> --json | ConvertFrom-JSON | Format-Table | |
| # show all servers | |
| ( profitbricks datacenter list --json | ConvertFrom-JSON ) | ForEach { profitbricks server list --datacenterid $_.Id --json | ConvertFrom-JSON } | Format-Table |
This file contains hidden or 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
| Do { | |
| # read all datacenter | |
| $datacenter = profitbricks datacenter list --json | ConvertFrom-JSON | |
| # create empty array for all servers | |
| $server=@() | |
| # run through every datacenter and append every single server to a list | |
| $datacenter | ForEach { | |
| # append data from the datacenter | |
| $dataCenterId = $_.Id | |
| $dataCenterName = $_.Name | |
| $dataCenterLocation = $_.Location | |
| $dcserver = profitbricks server list --datacenterid $dataCenterId --json | ConvertFrom-JSON | |
| $dcserver | ForEach { | |
| $_ | Add-Member -Type NoteProperty -Name "DCID" -Value $dataCenterId | |
| $_ | Add-Member -Type NoteProperty -Name "DCName" -Value $dataCenterName | |
| $_ | Add-Member -Type NoteProperty -Name "DCLocation" -Value $dataCenterLocation | |
| $server += $_ | |
| } | |
| # show results of the last call | |
| $dcserver | |
| } | |
| # show result in a nice formatted table popup | |
| $server | Sort -Property State | Select State, Cores, Memory, Name, DCName, Id, DCID, DCLocation, AvailabilityZone | Out-GridView | |
| Start-Sleep 30 | |
| # as long as powershell window not closed | |
| } While ( 1 -lt 10 ) | |
| # Wait until key pressed | |
| Write-Host "Press any key to continue ..." | |
| $x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") |
This file contains hidden or 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
| # read all datacenter | |
| $datacenter = profitbricks datacenter list --json | ConvertFrom-JSON | |
| # create empty array for all servers | |
| $server=@() | |
| # run through every datacenter and append every single server to a list | |
| $datacenter | ForEach { | |
| # append data from the datacenter | |
| $dataCenterId = $_.Id | |
| $dataCenterName = $_.Name | |
| $dataCenterLocation = $_.Location | |
| $dcserver = profitbricks server list --datacenterid $dataCenterId --json | ConvertFrom-JSON | |
| $dcserver | ForEach { | |
| $_ | Add-Member -Type NoteProperty -Name "DCID" -Value $dataCenterId | |
| $_ | Add-Member -Type NoteProperty -Name "DCName" -Value $dataCenterName | |
| $_ | Add-Member -Type NoteProperty -Name "DCLocation" -Value $dataCenterLocation | |
| $server += $_ | |
| } | |
| # show results of the last call | |
| $dcserver | |
| } | |
| # show result in a nice formatted table popup | |
| $server | Sort -Property State | Select State, Cores, Memory, Name, DCName, Id, DCID, DCLocation, AvailabilityZone | Out-GridView -PassThru | ForEach { profitbricks server start --datacenterid $_.DCID -i $_.Id } | |
| # Wait until key pressed | |
| #Write-Host "Press any key to continue ..." | |
| #$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | |
This file contains hidden or 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
| # read all datacenter | |
| $datacenter = profitbricks datacenter list --json | ConvertFrom-JSON | |
| # create empty array for all servers | |
| $server=@() | |
| # run through every datacenter and append every single server to a list | |
| $datacenter | ForEach { | |
| # append data from the datacenter | |
| $dataCenterId = $_.Id | |
| $dataCenterName = $_.Name | |
| $dataCenterLocation = $_.Location | |
| $dcserver = profitbricks server list --datacenterid $dataCenterId --json | ConvertFrom-JSON | |
| $dcserver | ForEach { | |
| $_ | Add-Member -Type NoteProperty -Name "DCID" -Value $dataCenterId | |
| $_ | Add-Member -Type NoteProperty -Name "DCName" -Value $dataCenterName | |
| $_ | Add-Member -Type NoteProperty -Name "DCLocation" -Value $dataCenterLocation | |
| $server += $_ | |
| } | |
| # show results of the last call | |
| $dcserver | |
| } | |
| # show result in a nice formatted table popup | |
| $server | Sort -Property State | Select State, Cores, Memory, Name, DCName, Id, DCID, DCLocation, AvailabilityZone | Out-GridView -PassThru | ForEach { profitbricks server start --datacenterid $_.DCID -i $_.Id } | |
| # Wait until key pressed | |
| #Write-Host "Press any key to continue ..." | |
| #$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment