├── NOTICE ├── .gitattributes ├── DoPx.psm1 ├── functions ├── Get-DoPxDefaultAccessToken.ps1 ├── Clear-DoPxDefaultAccessToken.ps1 ├── Set-DoPxDefaultAccessToken.ps1 ├── Get-DoPxSize.ps1 ├── Get-DoPxRegion.ps1 ├── Remove-DoPxBackup.ps1 ├── Remove-DoPxSnapshot.ps1 ├── Add-DoPxSshKey.ps1 ├── Remove-DoPxDomain.ps1 ├── Remove-DoPxDnsRecord.ps1 ├── Remove-DoPxDroplet.ps1 ├── Receive-DoPxAction.ps1 ├── Rename-DoPxDnsRecord.ps1 ├── Start-DoPxDroplet.ps1 ├── Rename-DoPxBackup.ps1 ├── Get-DoPxKernel.ps1 ├── Rename-DoPxSnapshot.ps1 ├── Copy-DoPxBackup.ps1 ├── Get-DoPxDomain.ps1 ├── Get-DoPxImage.ps1 ├── Copy-DoPxSnapshot.ps1 ├── Get-DoPxDroplet.ps1 ├── New-DoPxSnapshot.ps1 ├── Disable-DoPxDropletOption.ps1 ├── Remove-DoPxSshKey.ps1 ├── Restore-DoPxBackup.ps1 ├── Restore-DoPxSnapshot.ps1 ├── Rename-DoPxDroplet.ps1 ├── Update-DoPxKernel.ps1 ├── Resize-DoPxDroplet.ps1 ├── Rename-DoPxSshKey.ps1 ├── Get-DoPxBackup.ps1 ├── Get-DoPxSshKey.ps1 ├── Get-DoPxSnapshot.ps1 ├── Add-DoPxDomain.ps1 ├── Wait-DoPxAction.ps1 ├── Restart-DoPxDroplet.ps1 ├── Stop-DoPxDroplet.ps1 └── Enable-DoPxDropletOption.ps1 └── helpers ├── Get-DoPxWebRequestHeader.ps1 ├── New-DoPxObject.ps1 ├── ConvertTo-DoPxObject.ps1 ├── Remove-DoPxObject.ps1 ├── Set-DoPxObject.ps1 ├── Get-DoPxObject.ps1 └── Invoke-DoPxObjectAction.ps1 /NOTICE: -------------------------------------------------------------------------------- 1 | DoPx 2 | Copyright 2014 Kirk Munro 3 | 4 | This product includes software developed by Kirk Munro (http://kirkmunro.com). -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set default behaviour, in case users don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files we want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.md text 7 | *.gitattributes text 8 | 9 | # Declare files that will always have CRLF line endings on checkout. 10 | *.ps1 text eol=crlf 11 | *.psm1 text eol=crlf 12 | *.psd1 text eol=crlf 13 | *.psc1 text eol=crlf 14 | *.ps1xml text eol=crlf 15 | *.clixml text eol=crlf 16 | *.xml text eol=crlf 17 | *.txt text eol=crlf 18 | 19 | # Denote all files that are truly binary and should not be modified. 20 | *.dll binary 21 | *.exe binary -------------------------------------------------------------------------------- /DoPx.psm1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | #region Initialize the module. 24 | 25 | Invoke-Snippet -Name Module.Initialize 26 | 27 | #endregion 28 | 29 | #region Initialize module-specific properties. 30 | 31 | $DigitalOceanEndpointUri = 'https://api.digitalocean.com/v2' 32 | 33 | #endregion 34 | 35 | #region Import helper (private) function definitions. 36 | 37 | Invoke-Snippet -Name ScriptFile.Import -Parameters @{ 38 | Path = Join-Path -Path $PSModuleRoot -ChildPath helpers 39 | } 40 | 41 | #endregion 42 | 43 | #region Import public function definitions. 44 | 45 | Invoke-Snippet -Name ScriptFile.Import -Parameters @{ 46 | Path = Join-Path -Path $PSModuleRoot -ChildPath functions 47 | } 48 | 49 | #endregion -------------------------------------------------------------------------------- /functions/Get-DoPxDefaultAccessToken.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the access token that is being used by default in other DoPx commands. 26 | .DESCRIPTION 27 | The Get-DoPxDefaultAccessToken command gets the access token that is being used by default in other DoPx commands. 28 | .INPUTS 29 | None 30 | .OUTPUTS 31 | System.Security.SecureString 32 | .NOTES 33 | To learn more about the DigitalOcean REST API security, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> Get-DoPxDefaultAccessToken 36 | 37 | This command gets the access token that is being be used by default in all other DoPx commands. 38 | .LINK 39 | Clear-DoPxDefaultAccessToken 40 | .LINK 41 | Set-DoPxDefaultAccessToken 42 | #> 43 | function Get-DoPxDefaultAccessToken { 44 | [CmdletBinding()] 45 | [OutputType([System.Security.SecureString])] 46 | param() 47 | try { 48 | #region If there is a default access token set for the module, return it. 49 | 50 | $Script:PSDefaultParameterValues['Get-DoPxWebRequestHeader:AccessToken'] 51 | 52 | #endregion 53 | } catch { 54 | $PSCmdlet.ThrowTerminatingError($_) 55 | } 56 | } 57 | 58 | Export-ModuleMember -Function Get-DoPxDefaultAccessToken -------------------------------------------------------------------------------- /helpers/Get-DoPxWebRequestHeader.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | function Get-DoPxWebRequestHeader { 24 | [CmdletBinding()] 25 | [OutputType([System.Collections.Hashtable])] 26 | param( 27 | [Parameter(Mandatory=$true)] 28 | [ValidateNotNull()] 29 | [System.Security.SecureString] 30 | $AccessToken 31 | ) 32 | try { 33 | #region Get a BSTR pointer to the access token. 34 | 35 | $bstrAccessToken = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($AccessToken) 36 | 37 | #endregion 38 | 39 | #region Create the web request header with the default values that are always passed in. 40 | 41 | $headers = @{ 42 | # Always specify that we want JSON data (even errors should come back as JSON) 43 | 'Accept' = 'application/json' 44 | # Authorization token 45 | 'Authorization' = "Bearer $([Runtime.InteropServices.Marshal]::PtrToStringAuto($bstrAccessToken))" 46 | } 47 | 48 | #endregion 49 | 50 | #region Return the headers to the caller. 51 | 52 | $headers 53 | 54 | #endregion 55 | } catch { 56 | $PSCmdlet.ThrowTerminatingError($_) 57 | } finally { 58 | #region Free our BSTR pointer. 59 | 60 | if ($bstrAccessToken -ne $null) { 61 | [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($bstrAccessToken) 62 | } 63 | 64 | #endregion 65 | } 66 | } -------------------------------------------------------------------------------- /functions/Clear-DoPxDefaultAccessToken.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Clears the access token that is being used by default in other DoPx commands from memory. 26 | .DESCRIPTION 27 | The Clear-DoPxDefaultAccessToken command clears the access token that is being used by default in other DoPx commands from memory. 28 | .INPUTS 29 | None 30 | .OUTPUTS 31 | None 32 | .NOTES 33 | To learn more about the DigitalOcean REST API security, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> Clear-DoPxDefaultAccessToken 36 | 37 | This command clears the access token that is being be used by default in all other DoPx commands. After running this command, you must either explicitly use an access token in other DoPx commands or you must invoke Set-DoPxDefaultAccessToken to set a new default access token. 38 | .LINK 39 | Get-DoPxDefaultAccessToken 40 | .LINK 41 | Set-DoPxDefaultAccessToken 42 | #> 43 | function Clear-DoPxDefaultAccessToken { 44 | [CmdletBinding(SupportsShouldProcess=$true)] 45 | [OutputType([System.Void])] 46 | param() 47 | try { 48 | #region If there is an access token stored in the module scope, remove it. 49 | 50 | if ($PSCmdlet.ShouldProcess('AccessToken')) { 51 | $Script:PSDefaultParameterValues.Remove('Get-DoPxWebRequestHeader:AccessToken') 52 | } 53 | 54 | #endregion 55 | } catch { 56 | $PSCmdlet.ThrowTerminatingError($_) 57 | } 58 | } 59 | 60 | Export-ModuleMember -Function Clear-DoPxDefaultAccessToken -------------------------------------------------------------------------------- /functions/Set-DoPxDefaultAccessToken.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Set the access token that will be used by default in other DoPx commands. 26 | .DESCRIPTION 27 | The Set-DoPxDefaultAccessToken command sets the access token that will be used by default in other DoPx commands. 28 | .INPUTS 29 | None 30 | .OUTPUTS 31 | None 32 | .NOTES 33 | To learn more about the DigitalOcean REST API security, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | 38 | This command sets the access token that will be used by default in all other DoPx commands. 39 | .LINK 40 | Clear-DoPxDefaultAccessToken 41 | .LINK 42 | Get-DoPxDefaultAccessToken 43 | #> 44 | function Set-DoPxDefaultAccessToken { 45 | [CmdletBinding(SupportsShouldProcess=$true)] 46 | [OutputType([System.Void])] 47 | param( 48 | # The access token for your DigitalOcean account, in secure string format. 49 | [Parameter(Mandatory=$true)] 50 | [ValidateNotNull()] 51 | [System.Security.SecureString] 52 | $AccessToken, 53 | 54 | # Passes the access token to the pipeline. By default, this command does not generate any output. 55 | [Parameter()] 56 | [System.Management.Automation.SwitchParameter] 57 | $PassThru 58 | ) 59 | try { 60 | #region Store the access token that was provided in the module scope. 61 | 62 | if ($PSCmdlet.ShouldProcess('AccessToken')) { 63 | $Script:PSDefaultParameterValues['Get-DoPxWebRequestHeader:AccessToken'] = $AccessToken 64 | } 65 | 66 | #endregion 67 | 68 | #region If PassThru was requested, return the access token to the caller. 69 | 70 | if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('PassThru') -and $PassThru) { 71 | Get-DoPxDefaultAccessToken 72 | } 73 | 74 | #endregion 75 | } catch { 76 | $PSCmdlet.ThrowTerminatingError($_) 77 | } 78 | } 79 | 80 | Export-ModuleMember -Function Set-DoPxDefaultAccessToken -------------------------------------------------------------------------------- /functions/Get-DoPxSize.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the sizes that are available for DigitalOcean droplets. 26 | .DESCRIPTION 27 | The Get-DoPxSize command gets the sizes that are available for DigitalOcean droplets. 28 | .PARAMETER First 29 | Get only the specified number of sizes. 30 | .PARAMETER Skip 31 | Skip the specified number of sizes. If this parameter is used in conjunction with the First parameter, the specified number of sizes will be skipped before the paging support starts counting the first sizes to return. 32 | .PARAMETER IncludeTotalCount 33 | Return the total count of sizes that will be returned before returning the sizes themselves. 34 | .INPUTS 35 | None 36 | .OUTPUTS 37 | digitalocean.size 38 | .NOTES 39 | This command sends an HTTP GET request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxSize 44 | 45 | This command gets all sizes that are available for DigitalOcean droplets. 46 | #> 47 | function Get-DoPxSize { 48 | [CmdletBinding(SupportsPaging=$true)] 49 | [OutputType('digitalocean.size')] 50 | param( 51 | # The access token for your DigitalOcean account, in secure string format. 52 | [Parameter()] 53 | [ValidateNotNull()] 54 | [System.Security.SecureString] 55 | $AccessToken 56 | ) 57 | begin { 58 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 59 | CommandName = 'Get-DoPxObject' 60 | CommandType = 'Function' 61 | PreProcessScriptBlock = { 62 | #region Add additional required parameters to the BoundParameters hashtable. 63 | 64 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'sizes' 65 | 66 | #endregion 67 | } 68 | } 69 | } 70 | process { 71 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 72 | } 73 | end { 74 | Invoke-Snippet -Name ProxyFunction.End 75 | } 76 | } 77 | 78 | Export-ModuleMember -Function Get-DoPxSize -------------------------------------------------------------------------------- /functions/Get-DoPxRegion.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the regions that are available in DigitalOcean. 26 | .DESCRIPTION 27 | The Get-DoPxRegion command gets the regions that are available in DigitalOcean. 28 | .PARAMETER First 29 | Get only the specified number of regions. 30 | .PARAMETER Skip 31 | Skip the specified number of regions. If this parameter is used in conjunction with the First parameter, the specified number of regions will be skipped before the paging support starts counting the first regions to return. 32 | .PARAMETER IncludeTotalCount 33 | Return the total count of regions that will be returned before returning the regions themselves. 34 | .INPUTS 35 | None 36 | .OUTPUTS 37 | digitalocean.region 38 | .NOTES 39 | This command sends an HTTP GET request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxRegion 44 | 45 | This command gets all regions that are available in DigitalOcean. 46 | #> 47 | function Get-DoPxRegion { 48 | [CmdletBinding(SupportsPaging=$true)] 49 | [OutputType('digitalocean.region')] 50 | param( 51 | # The access token for your DigitalOcean account, in secure string format. 52 | [Parameter()] 53 | [ValidateNotNull()] 54 | [System.Security.SecureString] 55 | $AccessToken 56 | ) 57 | begin { 58 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 59 | CommandName = 'Get-DoPxObject' 60 | CommandType = 'Function' 61 | PreProcessScriptBlock = { 62 | #region Add additional required parameters to the BoundParameters hashtable. 63 | 64 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'regions' 65 | 66 | #endregion 67 | } 68 | } 69 | } 70 | process { 71 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 72 | } 73 | end { 74 | Invoke-Snippet -Name ProxyFunction.End 75 | } 76 | } 77 | 78 | Export-ModuleMember -Function Get-DoPxRegion -------------------------------------------------------------------------------- /functions/Remove-DoPxBackup.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Removes a backup from your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Remove-DoPxImage command removes a backup from your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.backup 30 | .OUTPUTS 31 | none 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Remove-DoPxBackup -Id 7606405 38 | 39 | This command removes the backup with id 7606405 from your DigitalOcean environment. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxBackup | Remove-DoPxBackup 44 | 45 | This command removes all backups from your DigitalOcean environment. 46 | .LINK 47 | Copy-DoPxBackup 48 | .LINK 49 | Get-DoPxBackup 50 | .LINK 51 | New-DoPxBackup 52 | .LINK 53 | Rename-DoPxBackup 54 | .LINK 55 | Restore-DoPxBackup 56 | #> 57 | function Remove-DoPxBackup { 58 | [CmdletBinding(SupportsShouldProcess=$true)] 59 | [OutputType([System.Void])] 60 | param( 61 | # The numeric id of one or more backups. 62 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 63 | [ValidateNotNull()] 64 | [ValidateRange(1,[System.Int32]::MaxValue)] 65 | [System.Int32[]] 66 | $Id, 67 | 68 | # The access token for your DigitalOcean environment, in secure string format. 69 | [Parameter()] 70 | [ValidateNotNull()] 71 | [System.Security.SecureString] 72 | $AccessToken 73 | ) 74 | process { 75 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 76 | CommandName = 'Remove-DoPxObject' 77 | CommandType = 'Function' 78 | PreProcessScriptBlock = { 79 | #region Add additional required parameters to the BoundParameters hashtable. 80 | 81 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'images' 82 | 83 | #endregion 84 | } 85 | } 86 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 87 | Invoke-Snippet -Name ProxyFunction.End 88 | } 89 | } 90 | 91 | Export-ModuleMember -Function Remove-DoPxBackup -------------------------------------------------------------------------------- /functions/Remove-DoPxSnapshot.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Removes a snapshot from your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Remove-DoPxImage command removes a snapshot from your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.snapshot 30 | .OUTPUTS 31 | none 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Remove-DoPxSnapshot -Id 7606405 38 | 39 | This command removes the snapshot with id 7606405 from your DigitalOcean environment. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxSnapshot | Remove-DoPxSnapshot 44 | 45 | This command removes all snapshots from your DigitalOcean environment. 46 | .LINK 47 | Copy-DoPxSnapshot 48 | .LINK 49 | Get-DoPxSnapshot 50 | .LINK 51 | New-DoPxSnapshot 52 | .LINK 53 | Rename-DoPxSnapshot 54 | .LINK 55 | Restore-DoPxSnapshot 56 | #> 57 | function Remove-DoPxSnapshot { 58 | [CmdletBinding(SupportsShouldProcess=$true)] 59 | [OutputType([System.Void])] 60 | param( 61 | # The numeric id of one or more snapshots. 62 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 63 | [ValidateNotNull()] 64 | [ValidateRange(1,[System.Int32]::MaxValue)] 65 | [System.Int32[]] 66 | $Id, 67 | 68 | # The access token for your DigitalOcean environment, in secure string format. 69 | [Parameter()] 70 | [ValidateNotNull()] 71 | [System.Security.SecureString] 72 | $AccessToken 73 | ) 74 | process { 75 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 76 | CommandName = 'Remove-DoPxObject' 77 | CommandType = 'Function' 78 | PreProcessScriptBlock = { 79 | #region Add additional required parameters to the BoundParameters hashtable. 80 | 81 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'images' 82 | 83 | #endregion 84 | } 85 | } 86 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 87 | Invoke-Snippet -Name ProxyFunction.End 88 | } 89 | } 90 | 91 | Export-ModuleMember -Function Remove-DoPxSnapshot -------------------------------------------------------------------------------- /functions/Add-DoPxSshKey.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Adds an ssh key to your DigitalOcean account. 26 | .DESCRIPTION 27 | The Add-DoPxSshKey command adds an ssh keys to your DigitalOcean account. 28 | .INPUTS 29 | None 30 | .OUTPUTS 31 | digitalocean.sshkey 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Add-DoPxSshKey -Name RailsKey -PublicKey $publicKey 38 | 39 | This command adds an ssh key named RailsKey that is identified by $publicKey to your DigitalOcean account. 40 | .LINK 41 | Get-DoPxSshKey 42 | .LINK 43 | Rename-DoPxSshKey 44 | .LINK 45 | Remove-DoPxSshKey 46 | #> 47 | function Add-DoPxSshKey { 48 | [CmdletBinding(SupportsShouldProcess=$true)] 49 | [OutputType('digitalocean.sshkey')] 50 | param( 51 | # The name of the ssh key. 52 | [Parameter(Position=0, Mandatory=$true)] 53 | [ValidateNotNullOrEmpty()] 54 | [System.String] 55 | $Name, 56 | 57 | # The public key. 58 | [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 59 | [ValidateNotNullOrEmpty()] 60 | [System.String] 61 | $PublicKey, 62 | 63 | # The access token for your DigitalOcean account, in secure string format. 64 | [Parameter()] 65 | [ValidateNotNull()] 66 | [System.Security.SecureString] 67 | $AccessToken 68 | ) 69 | process { 70 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 71 | CommandName = 'New-DoPxObject' 72 | CommandType = 'Function' 73 | PreProcessScriptBlock = { 74 | #region Identify the endpoint that is used when adding an ssh key. 75 | 76 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'account/keys' 77 | 78 | #endregion 79 | 80 | #region Identify the properties that will be assigned to the ssh key you are adding. 81 | 82 | $PSCmdlet.MyInvocation.BoundParameters['Property'] = @{ 83 | name = $Name 84 | public_key = $PublicKey 85 | } 86 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Name') > $null 87 | $PSCmdlet.MyInvocation.BoundParameters.Remove('PublicKey') > $null 88 | 89 | #endregion 90 | } 91 | } 92 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 93 | Invoke-Snippet -Name ProxyFunction.End 94 | } 95 | } 96 | 97 | Export-ModuleMember -Function Add-DoPxSshKey -------------------------------------------------------------------------------- /functions/Remove-DoPxDomain.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Removes one or more domains that have been added to your DigitalOcean environment 26 | .DESCRIPTION 27 | The Remove-DoPxDomain command removes one or more domains that have been added to your DigitalOcean environment 28 | 29 | You can use Remove-DoPxDomain command to remove specific domains by passing the domain names to the Name parameter. 30 | .INPUTS 31 | digitalocean.domain 32 | .OUTPUTS 33 | None 34 | .NOTES 35 | This command sends an HTTP DELETE request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 36 | .EXAMPLE 37 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 38 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 39 | PS C:\> Remove-DoPxDomain -Name example.com 40 | 41 | This command removes the domain with name "example.com" from your DigitalOcean environment 42 | .EXAMPLE 43 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 44 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 45 | PS C:\> Get-DoPxDomain | Remove-DoPxDomain 46 | 47 | This command removes all domains from your DigitalOcean environment 48 | .LINK 49 | Add-DoPxDomain 50 | .LINK 51 | Get-DoPxDomain 52 | .LINK 53 | Rename-DoPxDomain 54 | #> 55 | function Remove-DoPxDomain { 56 | [CmdletBinding(SupportsShouldProcess=$true)] 57 | [OutputType([System.Void])] 58 | param( 59 | # The name of the domain. 60 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 61 | [ValidateNotNullOrEmpty()] 62 | [System.String[]] 63 | $Name, 64 | 65 | # The access token for your DigitalOcean account, in secure string format. 66 | [Parameter()] 67 | [ValidateNotNull()] 68 | [System.Security.SecureString] 69 | $AccessToken 70 | ) 71 | process { 72 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 73 | CommandName = 'Remove-DoPxObject' 74 | CommandType = 'Function' 75 | PreProcessScriptBlock = { 76 | #region Set up the ID properly. 77 | 78 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $Name 79 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Name') > $null 80 | 81 | #endregion 82 | 83 | #region Add additional required parameters to the BoundParameters hashtable. 84 | 85 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'domains' 86 | 87 | #endregion 88 | } 89 | } 90 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 91 | Invoke-Snippet -Name ProxyFunction.End 92 | } 93 | } 94 | 95 | Export-ModuleMember -Function Remove-DoPxDomain -------------------------------------------------------------------------------- /functions/Remove-DoPxDnsRecord.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Removes one or more DNS records that have been created in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Remove-DoPxDnsRecord command removes one or more DNS records that have been created in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.domainrecord 30 | .OUTPUTS 31 | none 32 | .NOTES 33 | This command sends an HTTP DELETE request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Remove-DoPxDnsRecord -DomainName example.com -Id 4536712 38 | 39 | This command removes the DNS record with id 4536712 that was created for the "example.com" domain. 40 | .LINK 41 | Add-DoPxDnsRecord 42 | .LINK 43 | Get-DoPxDnsRecord 44 | .LINK 45 | Rename-DoPxDnsRecord 46 | #> 47 | function Remove-DoPxDnsRecord { 48 | [CmdletBinding(SupportsShouldProcess=$true)] 49 | [OutputType([System.Void])] 50 | param( 51 | # The name of a domain with records you want to remove. 52 | [Parameter(Position=0, Mandatory=$true)] 53 | [ValidateNotNullOrEmpty()] 54 | [System.String[]] 55 | $DomainName, 56 | 57 | # The DNS record IDs you want removed. 58 | [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 59 | [ValidateNotNull()] 60 | [ValidateRange(1,[System.Int32]::MaxValue)] 61 | [System.Int32[]] 62 | $Id, 63 | 64 | # The access token for your DigitalOcean account, in secure string format. 65 | [Parameter()] 66 | [ValidateNotNull()] 67 | [System.Security.SecureString] 68 | $AccessToken 69 | ) 70 | process { 71 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 72 | CommandName = 'Remove-DoPxObject' 73 | CommandType = 'Function' 74 | PreProcessScriptBlock = { 75 | #region Reorganize the input parameters. 76 | 77 | $PSCmdlet.MyInvocation.BoundParameters['RelatedObjectId'] = $Id 78 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DomainName 79 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DomainName') > $null 80 | 81 | #endregion 82 | 83 | #region Add additional required parameters to the BoundParameters hashtable. 84 | 85 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'domains' 86 | $PSCmdlet.MyInvocation.BoundParameters['RelatedObjectUri'] = 'records' 87 | 88 | #endregion 89 | } 90 | } 91 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 92 | Invoke-Snippet -Name ProxyFunction.End 93 | } 94 | } 95 | 96 | Export-ModuleMember -Function Remove-DoPxDnsRecord -------------------------------------------------------------------------------- /functions/Remove-DoPxDroplet.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Removes one or more droplets from your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Remove-DoPxDroplet command removes one or more droplets from your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | none 32 | .NOTES 33 | This command sends an HTTP DELETE request that includes your access token to the DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Remove-DoPxDroplet -Id 4849480 38 | 39 | This command removes the droplet with id 4849480 from the DigitalOcean environment identified by the access token that is provided. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxDroplet | Remove-DoPxDroplet 44 | 45 | This command removes the all droplets from the DigitalOcean environment identified by the access token that is provided. 46 | .LINK 47 | Disable-DoPxDropletOption 48 | .LINK 49 | Enable-DoPxDropletOption 50 | .LINK 51 | Get-DoPxBackup 52 | .LINK 53 | Get-DoPxDroplet 54 | .LINK 55 | Get-DoPxKernel 56 | .LINK 57 | Get-DoPxSnapshot 58 | .LINK 59 | New-DoPxDroplet 60 | .LINK 61 | Rename-DoPxDroplet 62 | .LINK 63 | Reset-DoPxDroplet 64 | .LINK 65 | Resize-DoPxDroplet 66 | .LINK 67 | Restart-DoPxDroplet 68 | .LINK 69 | Start-DoPxDroplet 70 | .LINK 71 | Stop-DoPxDroplet 72 | #> 73 | function Remove-DoPxDroplet { 74 | [CmdletBinding(SupportsShouldProcess=$true)] 75 | [OutputType('digitalocean.droplet')] 76 | param( 77 | # The numeric id of the droplet. 78 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 79 | [ValidateNotNull()] 80 | [ValidateRange(1,[System.Int32]::MaxValue)] 81 | [System.Int32[]] 82 | $Id, 83 | 84 | # The access token for your DigitalOcean account, in secure string format. 85 | [Parameter()] 86 | [ValidateNotNull()] 87 | [System.Security.SecureString] 88 | $AccessToken 89 | ) 90 | process { 91 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 92 | CommandName = 'Remove-DoPxObject' 93 | CommandType = 'Function' 94 | PreProcessScriptBlock = { 95 | #region Add additional required parameters to the BoundParameters hashtable. 96 | 97 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 98 | 99 | #endregion 100 | } 101 | } 102 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 103 | Invoke-Snippet -Name ProxyFunction.End 104 | } 105 | } 106 | 107 | Export-ModuleMember -Function Remove-DoPxDroplet -------------------------------------------------------------------------------- /helpers/New-DoPxObject.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | function New-DoPxObject { 24 | [CmdletBinding(SupportsShouldProcess=$true)] 25 | [OutputType('digitalocean.object')] 26 | param( 27 | [Parameter(Position=0, Mandatory=$true)] 28 | [ValidateNotNullOrEmpty()] 29 | [System.String] 30 | $RelativeUri, 31 | 32 | [Parameter(Position=1)] 33 | [ValidateNotNullOrEmpty()] 34 | [System.String[]] 35 | $Id, 36 | 37 | [Parameter(Position=2)] 38 | [ValidateNotNullOrEmpty()] 39 | [System.String] 40 | $RelatedObjectUri, 41 | 42 | [Parameter(Mandatory=$true)] 43 | [ValidateNotNullOrEmpty()] 44 | [Alias('PropertyValues')] 45 | [System.Collections.Hashtable] 46 | $Property, 47 | 48 | [Parameter()] 49 | [ValidateNotNull()] 50 | [System.Security.SecureString] 51 | $AccessToken 52 | ) 53 | try { 54 | #region If Id is used without the RelatedObjectUri parameter, raise an error. 55 | 56 | $PSCmdlet.ValidateParameterDependency('Id','RelatedObjectUri') 57 | 58 | #endregion 59 | 60 | #region Add the relative uri with the endpoint prefix. 61 | 62 | $uri = "${script:DigitalOceanEndpointUri}/$($RelativeUri -replace '^/+|/+$')" 63 | 64 | #endregion 65 | 66 | #region Identify the passthru ShouldProcess parameters. 67 | 68 | $shouldProcessParameters = $PSCmdlet.GetBoundShouldProcessParameters() 69 | 70 | #endregion 71 | 72 | #region Prefix the Uri parameters with a slash if not present. 73 | 74 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Id')) { 75 | $internalId = '' -as [System.String[]] 76 | } else { 77 | $internalId = $Id -replace '^([^/])','/$1' -as $Id.GetType() 78 | } 79 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('RelatedObjectUri')) { 80 | $internalRelatedObjectUri = '' -as [System.String] 81 | } else { 82 | $internalRelatedObjectUri = $RelatedObjectUri -replace '^([^/])','/$1' -as $RelatedObjectUri.GetType() 83 | } 84 | 85 | #endregion 86 | 87 | #region Initialize the web request headers. 88 | 89 | $accessTokenParameter = $PSCmdlet.GetSplattableParameters('AccessToken') 90 | $headers = Get-DoPxWebRequestHeader @accessTokenParameter 91 | 92 | #endregion 93 | 94 | foreach ($item in $internalId) { 95 | #region Construct the Uri according to the parameter values used in this iteration. 96 | 97 | $endpointUri = $uri 98 | if ($item) { 99 | $endpointUri += $item 100 | } 101 | if ($internalRelatedObjectUri) { 102 | $endpointUri += $internalRelatedObjectUri 103 | } 104 | 105 | #endregion 106 | 107 | #region Invoke the web request. 108 | 109 | Invoke-DoPxWebRequest -Uri $endpointUri -Method Post -Headers $headers -Body $Property @shouldProcessParameters 110 | 111 | #endregion 112 | } 113 | } catch { 114 | $PSCmdlet.ThrowTerminatingError($_) 115 | } 116 | } 117 | 118 | Export-ModuleMember -Function New-DoPxObject -------------------------------------------------------------------------------- /functions/Receive-DoPxAction.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Returns the object associated with a completed action. 26 | .DESCRIPTION 27 | The Receive-DoPxAction command returns the object associated with a completed action. 28 | .INPUTS 29 | digitalocean.action 30 | .OUTPUTS 31 | digitalocean.object 32 | .NOTES 33 | This command sends an HTTP GET request that includes your access token to the DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Receive-DoPxAction -Id 51666486 38 | 39 | This command returns the object used to invoke the completed action with id 51666486. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxAction -Id 51666486 | Wait-Action | Receive-DoPxAction 44 | 45 | This command waits for the action with id 51666486 to finish running and then returns the object used to invoke that action. 46 | .LINK 47 | Get-DoPxAction 48 | .LINK 49 | Wait-DoPxAction 50 | #> 51 | function Receive-DoPxAction { 52 | [CmdletBinding(SupportsShouldProcess=$true)] 53 | [OutputType('digitalocean.object')] 54 | param( 55 | # The numeric id of the action. 56 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 57 | [ValidateNotNullOrEmpty()] 58 | [System.String] 59 | $Id, 60 | 61 | # The access token for your DigitalOcean account, in secure string format. 62 | [Parameter()] 63 | [ValidateNotNull()] 64 | [System.Security.SecureString] 65 | $AccessToken 66 | ) 67 | begin { 68 | try { 69 | #region Get a splattable AccessToken parameter. 70 | 71 | $accessTokenParameter = $PSCmdlet.GetSplattableParameters('AccessToken') 72 | 73 | #endregion 74 | } catch { 75 | $PSCmdlet.ThrowTerminatingError($_) 76 | } 77 | } 78 | process { 79 | try { 80 | #region Get the current state of the action. 81 | 82 | if ($_.PSTypeNames -contains 'digitalocean.action') { 83 | $action = $_ 84 | } else { 85 | $action = Get-DoPxAction -Id $Id @accessTokenParameter 86 | } 87 | 88 | #endregion 89 | 90 | #region If we have a completed action, return the object it was invoked on to the caller. 91 | 92 | if ($action -and ($action.completed_at -ne $null)) { 93 | $relativeUri = $action.resource_type 94 | if ($relativeUri -notmatch 's$') { 95 | $relativeUri = "${relativeUri}s" 96 | } 97 | Get-DoPxObject -RelativeUri $relativeUri -Id $action.resource_id @accessTokenParameter 98 | } 99 | 100 | #endregion 101 | } catch { 102 | $PSCmdlet.ThrowTerminatingError($_) 103 | } 104 | } 105 | } 106 | 107 | Export-ModuleMember -Function Receive-DoPxAction -------------------------------------------------------------------------------- /functions/Rename-DoPxDnsRecord.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Renames a DNS records in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Rename-DoPxDnsRecord command renames a DNS records in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.domainrecord 30 | .OUTPUTS 31 | digitalocean.domainrecord 32 | .NOTES 33 | This command sends an HTTP PUT request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Rename-DoPxDnsRecord -DomainName example.com -Id 4536712 -NewName IPv6 38 | 39 | This command sets the name of the DNS record with id 4536712 that was created for the "example.com" domain to "IPv6". 40 | .LINK 41 | Add-DoPxDnsRecord 42 | .LINK 43 | Get-DoPxDnsRecord 44 | .LINK 45 | Remove-DoPxDnsRecord 46 | #> 47 | function Rename-DoPxDnsRecord { 48 | [CmdletBinding(SupportsShouldProcess=$true)] 49 | [OutputType('digitalocean.domainrecord')] 50 | param( 51 | # The name of a domain with a DNS record that you want to rename. 52 | [Parameter(Position=0, Mandatory=$true)] 53 | [ValidateNotNullOrEmpty()] 54 | [System.String] 55 | $DomainName, 56 | 57 | # The id of the DNS record you want to rename. 58 | [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 59 | [ValidateNotNull()] 60 | [ValidateRange(1,[System.Int32]::MaxValue)] 61 | [System.Int32] 62 | $Id, 63 | 64 | # The new name that you want to assign to the DNS record. 65 | [Parameter(Position=2, Mandatory=$true)] 66 | [ValidateNotNullOrEmpty()] 67 | [System.String] 68 | $NewName, 69 | 70 | # The access token for your DigitalOcean account, in secure string format. 71 | [Parameter()] 72 | [ValidateNotNull()] 73 | [System.Security.SecureString] 74 | $AccessToken 75 | ) 76 | process { 77 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 78 | CommandName = 'Set-DoPxObject' 79 | CommandType = 'Function' 80 | PreProcessScriptBlock = { 81 | #region Reorganize the input parameters. 82 | 83 | $PSCmdlet.MyInvocation.BoundParameters['RelatedObjectId'] = $Id 84 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DomainName 85 | $PSCmdlet.MyInvocation.BoundParameters['Property'] = @{name=$NewName} 86 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DomainName') > $null 87 | $PSCmdlet.MyInvocation.BoundParameters.Remove('NewName') > $null 88 | 89 | #endregion 90 | 91 | #region Add additional required parameters to the BoundParameters hashtable. 92 | 93 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'domains' 94 | $PSCmdlet.MyInvocation.BoundParameters['RelatedObjectUri'] = 'records' 95 | 96 | #endregion 97 | } 98 | } 99 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 100 | Invoke-Snippet -Name ProxyFunction.End 101 | } 102 | } 103 | 104 | Export-ModuleMember -Function Rename-DoPxDnsRecord -------------------------------------------------------------------------------- /functions/Start-DoPxDroplet.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Starts a droplet that is currently turned off in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Start-DoPxDroplet command starts a droplet that is currently turned off in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Start-DoPxDroplet -Id 4849480 38 | 39 | This command starts the droplet with id 4849480. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxDroplet | Where-Object {$_.Status -eq 'off'} | Start-DoPxDroplet 44 | 45 | This command starts all droplets that are currently turned off. 46 | .LINK 47 | Disable-DoPxDropletOption 48 | .LINK 49 | Enable-DoPxDropletOption 50 | .LINK 51 | Get-DoPxBackup 52 | .LINK 53 | Get-DoPxDroplet 54 | .LINK 55 | Get-DoPxKernel 56 | .LINK 57 | Get-DoPxSnapshot 58 | .LINK 59 | New-DoPxDroplet 60 | .LINK 61 | Remove-DoPxDroplet 62 | .LINK 63 | Rename-DoPxDroplet 64 | .LINK 65 | Reset-DoPxDroplet 66 | .LINK 67 | Resize-DoPxDroplet 68 | .LINK 69 | Restart-DoPxDroplet 70 | .LINK 71 | Stop-DoPxDroplet 72 | #> 73 | function Start-DoPxDroplet { 74 | [CmdletBinding(SupportsShouldProcess=$true)] 75 | [OutputType('digitalocean.action')] 76 | [OutputType('digitalocean.droplet')] 77 | param( 78 | # The numeric id of one or more droplets that you want to start. 79 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 80 | [ValidateNotNull()] 81 | [ValidateRange(1,[System.Int32]::MaxValue)] 82 | [System.Int32[]] 83 | $Id, 84 | 85 | # The access token for your DigitalOcean environment, in secure string format. 86 | [Parameter()] 87 | [ValidateNotNull()] 88 | [System.Security.SecureString] 89 | $AccessToken, 90 | 91 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 92 | [Parameter()] 93 | [System.Management.Automation.SwitchParameter] 94 | $Wait 95 | ) 96 | process { 97 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 98 | CommandName = 'Invoke-DoPxObjectAction' 99 | CommandType = 'Function' 100 | PreProcessScriptBlock = { 101 | #region Add additional required parameters to the BoundParameters hashtable. 102 | 103 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'power_on' 104 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 105 | 106 | #endregion 107 | } 108 | } 109 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 110 | Invoke-Snippet -Name ProxyFunction.End 111 | } 112 | } 113 | 114 | Export-ModuleMember -Function Start-DoPxDroplet -------------------------------------------------------------------------------- /functions/Rename-DoPxBackup.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Renames a backup that was previously created in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Rename-DoPxBackup command renames a backup that was previously created in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.backup 30 | .OUTPUTS 31 | digitalocean.backup 32 | .NOTES 33 | This command sends an HTTP PUT request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Rename-DoPxBackup -Id 7606405 -NewName "Version 1.1" 38 | 39 | This command sets the name of the backup with id 7606405 to "Version 1.1". 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxImage | Rename-DoPxBackup -NewName {"Backup $($_.name)"} 44 | 45 | This command prepends "Backup " to the name of every backup in your DigitalOcean environment. 46 | .LINK 47 | Copy-DoPxBackup 48 | .LINK 49 | Get-DoPxBackup 50 | .LINK 51 | New-DoPxBackup 52 | .LINK 53 | Remove-DoPxBackup 54 | .LINK 55 | Restore-DoPxBackup 56 | #> 57 | function Rename-DoPxBackup { 58 | [CmdletBinding(SupportsShouldProcess=$true)] 59 | [OutputType('digitalocean.backup')] 60 | param( 61 | # The numeric id of the backup. 62 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 63 | [ValidateNotNull()] 64 | [ValidateRange(1,[System.Int32]::MaxValue)] 65 | [System.Int32] 66 | $Id, 67 | 68 | # The new name of the backup. 69 | [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 70 | [ValidateNotNullOrEmpty()] 71 | [System.String] 72 | $NewName, 73 | 74 | # The access token for your DigitalOcean account, in secure string format. 75 | [Parameter()] 76 | [ValidateNotNull()] 77 | [System.Security.SecureString] 78 | $AccessToken, 79 | 80 | # Returns the updated image object to the pipeline. By default, this command does not return anything. 81 | [Parameter()] 82 | [System.Management.Automation.SwitchParameter] 83 | $PassThru 84 | ) 85 | process { 86 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 87 | CommandName = 'Set-DoPxObject' 88 | CommandType = 'Function' 89 | PreProcessScriptBlock = { 90 | #region Replace the NewName bound parameter with a parameter hashtable for the action. 91 | 92 | $PSCmdlet.MyInvocation.BoundParameters['Property'] = @{name=$NewName} 93 | $PSCmdlet.MyInvocation.BoundParameters.Remove('NewName') > $null 94 | 95 | #endregion 96 | 97 | #region Add additional required parameters to the BoundParameters hashtable. 98 | 99 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'images' 100 | 101 | #endregion 102 | } 103 | } 104 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 105 | Invoke-Snippet -Name ProxyFunction.End 106 | } 107 | } 108 | 109 | Export-ModuleMember -Function Rename-DoPxBackup -------------------------------------------------------------------------------- /functions/Get-DoPxKernel.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the kernels that are available for a droplet in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Get-DoPxKernel command gets the kernels that are available for a droplet in your DigitalOcean environment. 28 | .PARAMETER First 29 | Get only the specified number of available kernels. 30 | .PARAMETER Skip 31 | Skip the specified number of available kernels. If this parameter is used in conjunction with the First parameter, the specified number of available kernels will be skipped before the paging support starts counting the first available kernels to return. 32 | .PARAMETER IncludeTotalCount 33 | Return the total count of available kernels that will be returned before returning the available kernels themselves. 34 | .INPUTS 35 | digitalocean.droplet 36 | .OUTPUTS 37 | digitalocean.kernel 38 | .NOTES 39 | This command sends an HTTP GET request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxKernel -DropletId 4849480 44 | 45 | This command gets a list of all available kernels for the droplet with ID 4849480. 46 | .EXAMPLE 47 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 48 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 49 | PS C:\> Get-DoPxDroplet -Id 4849480 | Get-DoPxKernel 50 | 51 | This command gets a list of all available kernels for the droplet with ID 4849480. 52 | .LINK 53 | Get-DoPxDroplet 54 | .LINK 55 | Update-DoPxKernel 56 | #> 57 | function Get-DoPxKernel { 58 | [CmdletBinding(SupportsPaging=$true)] 59 | [OutputType('digitalocean.kernel')] 60 | param( 61 | # The numeric id of the droplet for which you want the list of available kernels. 62 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 63 | [ValidateNotNullOrEmpty()] 64 | [ValidateRange(1,[System.Int32]::MaxValue)] 65 | [Alias('Id')] 66 | [System.Int32[]] 67 | $DropletId, 68 | 69 | # The access token for your DigitalOcean account, in secure string format. 70 | [Parameter()] 71 | [ValidateNotNull()] 72 | [System.Security.SecureString] 73 | $AccessToken 74 | ) 75 | process { 76 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 77 | CommandName = 'Get-DoPxObject' 78 | CommandType = 'Function' 79 | PreProcessScriptBlock = { 80 | #region Replace the DropletId bound parameter with the Id parameter. 81 | 82 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DropletId 83 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DropletId') > $null 84 | 85 | #endregion 86 | 87 | #region Add additional required parameters to the BoundParameters hashtable. 88 | 89 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 90 | $PSCmdlet.MyInvocation.BoundParameters['RelatedObjectUri'] = 'kernels' 91 | 92 | #endregion 93 | } 94 | } 95 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 96 | Invoke-Snippet -Name ProxyFunction.End 97 | } 98 | } 99 | 100 | Export-ModuleMember -Function Get-DoPxKernel -------------------------------------------------------------------------------- /functions/Rename-DoPxSnapshot.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Renames a snapshot that was previously created in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Rename-DoPxSnapshot command renames a snapshot that was previously created in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.snapshot 30 | .OUTPUTS 31 | digitalocean.snapshot 32 | .NOTES 33 | This command sends an HTTP PUT request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Rename-DoPxSnapshot -Id 7606405 -NewName "Version 1.1" 38 | 39 | This command sets the name of the snapshot with id 7606405 to "Version 1.1". 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxImage | Rename-DoPxSnapshot -NewName {"Snapshot $($_.name)"} 44 | 45 | This command prepends "Snapshot " to the name of every snapshot in your DigitalOcean environment. 46 | .LINK 47 | Copy-DoPxSnapshot 48 | .LINK 49 | Get-DoPxSnapshot 50 | .LINK 51 | New-DoPxSnapshot 52 | .LINK 53 | Remove-DoPxSnapshot 54 | .LINK 55 | Restore-DoPxSnapshot 56 | #> 57 | function Rename-DoPxSnapshot { 58 | [CmdletBinding(SupportsShouldProcess=$true)] 59 | [OutputType('digitalocean.snapshot')] 60 | param( 61 | # The numeric id of the snapshot. 62 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 63 | [ValidateNotNull()] 64 | [ValidateRange(1,[System.Int32]::MaxValue)] 65 | [System.Int32] 66 | $Id, 67 | 68 | # The new name of the snapshot. 69 | [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 70 | [ValidateNotNullOrEmpty()] 71 | [System.String] 72 | $NewName, 73 | 74 | # The access token for your DigitalOcean account, in secure string format. 75 | [Parameter()] 76 | [ValidateNotNull()] 77 | [System.Security.SecureString] 78 | $AccessToken, 79 | 80 | # Returns the updated image object to the pipeline. By default, this command does not return anything. 81 | [Parameter()] 82 | [System.Management.Automation.SwitchParameter] 83 | $PassThru 84 | ) 85 | process { 86 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 87 | CommandName = 'Set-DoPxObject' 88 | CommandType = 'Function' 89 | PreProcessScriptBlock = { 90 | #region Replace the NewName bound parameter with a parameter hashtable for the action. 91 | 92 | $PSCmdlet.MyInvocation.BoundParameters['Property'] = @{name=$NewName} 93 | $PSCmdlet.MyInvocation.BoundParameters.Remove('NewName') > $null 94 | 95 | #endregion 96 | 97 | #region Add additional required parameters to the BoundParameters hashtable. 98 | 99 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'images' 100 | 101 | #endregion 102 | } 103 | } 104 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 105 | Invoke-Snippet -Name ProxyFunction.End 106 | } 107 | } 108 | 109 | Export-ModuleMember -Function Rename-DoPxSnapshot -------------------------------------------------------------------------------- /functions/Copy-DoPxBackup.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Copies a backup in your DigitalOcean environment to a different region. 26 | .DESCRIPTION 27 | The Copy-DoPxBackup command copies a backup in your DigitalOcean environment to a different region. 28 | .INPUTS 29 | digitalocean.backup 30 | .OUTPUTS 31 | digitalocean.action,digitalocean.image 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Copy-DoPxBackup -Id 7606405 -RegionId nyc3 38 | 39 | This command copies backup id 7606405 to region "nyc3". 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxBackup | Copy-DoPxBackup -RegionId nyc3 44 | 45 | This command copies all backups in your DigitalOcean environment to region "nyc3". 46 | .LINK 47 | Get-DoPxBackup 48 | .LINK 49 | Remove-DoPxBackup 50 | .LINK 51 | Rename-DoPxBackup 52 | .LINK 53 | Restore-DoPxBackup 54 | #> 55 | function Copy-DoPxBackup { 56 | [CmdletBinding(SupportsShouldProcess=$true)] 57 | [OutputType('digitalocean.action')] 58 | [OutputType('digitalocean.image')] 59 | param( 60 | # The numeric id of one or more backups. 61 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 62 | [ValidateNotNull()] 63 | [ValidateRange(1,[System.Int32]::MaxValue)] 64 | [System.Int32[]] 65 | $Id, 66 | 67 | # The region to which those backups will be copied. 68 | [Parameter(Position=1, Mandatory=$true)] 69 | [ValidateNotNullOrEmpty()] 70 | [System.String] 71 | $RegionId, 72 | 73 | # The access token for your DigitalOcean environment, in secure string format. 74 | [Parameter()] 75 | [ValidateNotNull()] 76 | [System.Security.SecureString] 77 | $AccessToken, 78 | 79 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 80 | [Parameter()] 81 | [System.Management.Automation.SwitchParameter] 82 | $Wait 83 | ) 84 | process { 85 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 86 | CommandName = 'Invoke-DoPxObjectAction' 87 | CommandType = 'Function' 88 | PreProcessScriptBlock = { 89 | #region Replace the RegionId bound parameter with a parameter hashtable for the action. 90 | 91 | $PSCmdlet.MyInvocation.BoundParameters['Parameter'] = @{region=$RegionId} 92 | $PSCmdlet.MyInvocation.BoundParameters.Remove('RegionId') > $null 93 | 94 | #endregion 95 | 96 | #region Add additional required parameters to the BoundParameters hashtable. 97 | 98 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'transfer' 99 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'images' 100 | 101 | #endregion 102 | } 103 | } 104 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 105 | Invoke-Snippet -Name ProxyFunction.End 106 | } 107 | } 108 | 109 | Export-ModuleMember -Function Copy-DoPxBackup -------------------------------------------------------------------------------- /functions/Get-DoPxDomain.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the domains that have been added to your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Get-DoPxDomain command gets the domains that have been added to your DigitalOcean environment. 28 | 29 | Without the Id parameter, Get-DoPxDomain gets all of the domains that have been added to your DigitalOcean environment. You can also use Get-DoPxDomain command to get specific domains by passing the domain IDs to the Id parameter or fingerprints to the Fingerprint parameter. 30 | .PARAMETER First 31 | Get only the specified number of domains. 32 | .PARAMETER Skip 33 | Skip the specified number of domains. If this parameter is used in conjunction with the First parameter, the specified number of domains will be skipped before the paging support starts counting the first domains to return. 34 | .PARAMETER IncludeTotalCount 35 | Return the total count of domains that will be returned before returning the domains themselves. 36 | .INPUTS 37 | None 38 | .OUTPUTS 39 | digitalocean.domain 40 | .NOTES 41 | This command sends an HTTP GET request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 42 | .EXAMPLE 43 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 44 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 45 | PS C:\> Get-DoPxDomain 46 | 47 | This command gets all domains that have been added to your DigitalOcean environment. 48 | .EXAMPLE 49 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 50 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 51 | PS C:\> Get-DoPxDomain -Name example.com 52 | 53 | This command gets the domain with name "example.com" from your DigitalOcean environment. 54 | .LINK 55 | Add-DoPxDomain 56 | .LINK 57 | Remove-DoPxDomain 58 | #> 59 | function Get-DoPxDomain { 60 | [CmdletBinding(SupportsPaging=$true)] 61 | [OutputType('digitalocean.domain')] 62 | param( 63 | # The name of the domain. 64 | [Parameter(Position=0)] 65 | [ValidateNotNullOrEmpty()] 66 | [System.String[]] 67 | $Name, 68 | 69 | # The access token for your DigitalOcean environment, in secure string format. 70 | [Parameter()] 71 | [ValidateNotNull()] 72 | [System.Security.SecureString] 73 | $AccessToken 74 | ) 75 | begin { 76 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 77 | CommandName = 'Get-DoPxObject' 78 | CommandType = 'Function' 79 | PreProcessScriptBlock = { 80 | #region Set up the ID properly if a name is being used in the search. 81 | 82 | if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Name')) { 83 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $Name 84 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Name') > $null 85 | } 86 | 87 | #endregion 88 | 89 | #region Add additional required parameters to the BoundParameters hashtable. 90 | 91 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'domains' 92 | 93 | #endregion 94 | } 95 | } 96 | } 97 | process { 98 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 99 | } 100 | end { 101 | Invoke-Snippet -Name ProxyFunction.End 102 | } 103 | } 104 | 105 | Export-ModuleMember -Function Get-DoPxDomain -------------------------------------------------------------------------------- /functions/Get-DoPxImage.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the DigitalOcean images that are available in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Get-DoPxImage command gets the DigitalOcean images that are available in your DigitalOcean environment. These may be images of public Linux distributions or applications, snapshots of droplets, or automatic backup images of droplets. 28 | 29 | Without the Id parameter, Get-DoPxImage gets all of the images that are available in your DigitalOcean environment. You can also use Get-DoPxImage command to get specific images by passing the image IDs to the Id parameter. 30 | .PARAMETER First 31 | Get only the specified number of images. 32 | .PARAMETER Skip 33 | Skip the specified number of images. If this parameter is used in conjunction with the First parameter, the specified number of images will be skipped before the paging support starts counting the first images to return. 34 | .PARAMETER IncludeTotalCount 35 | Return the total count of images that will be returned before returning the images themselves. 36 | .INPUTS 37 | None 38 | .OUTPUTS 39 | digitalocean.image 40 | .NOTES 41 | This command sends an HTTP GET request that includes your access token to the DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 42 | .EXAMPLE 43 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 44 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 45 | PS C:\> Get-DoPxImage 46 | 47 | This command gets all images that are available in your DigitalOcean environment. 48 | .EXAMPLE 49 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 50 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 51 | PS C:\> Get-DoPxImage -Id 5142677 52 | 53 | This command gets the image with id 5142677 from your DigitalOcean environment. 54 | .EXAMPLE 55 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 56 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 57 | PS C:\> Get-DoPxImage -Id wordpress 58 | 59 | This command gets the image with the slug "wordpress" from your DigitalOcean environment. 60 | .LINK 61 | Get-DoPxBackup 62 | .LINK 63 | Get-DoPxSnapshot 64 | #> 65 | function Get-DoPxImage { 66 | [CmdletBinding(SupportsPaging=$true)] 67 | [OutputType('digitalocean.action')] 68 | param( 69 | # The numeric id or slug of the image. 70 | [Parameter(Position=0)] 71 | [ValidateNotNullOrEmpty()] 72 | [System.String[]] 73 | $Id, 74 | 75 | # The access token for your DigitalOcean account, in secure string format. 76 | [Parameter()] 77 | [ValidateNotNull()] 78 | [System.Security.SecureString] 79 | $AccessToken 80 | ) 81 | begin { 82 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 83 | CommandName = 'Get-DoPxObject' 84 | CommandType = 'Function' 85 | PreProcessScriptBlock = { 86 | #region Add additional required parameters to the BoundParameters hashtable. 87 | 88 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'images' 89 | 90 | #endregion 91 | } 92 | } 93 | } 94 | process { 95 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 96 | } 97 | end { 98 | Invoke-Snippet -Name ProxyFunction.End 99 | } 100 | } 101 | 102 | Export-ModuleMember -Function Get-DoPxImage -------------------------------------------------------------------------------- /helpers/ConvertTo-DoPxObject.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | function ConvertTo-DoPxObject { 24 | [CmdletBinding()] 25 | [OutputType('digitalocean.object')] 26 | param( 27 | [Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)] 28 | [ValidateNotNullOrEmpty()] 29 | [System.Object] 30 | $InputObject, 31 | 32 | [Parameter(Position=1, Mandatory=$true)] 33 | [ValidateNotNullOrEmpty()] 34 | [System.String] 35 | $Property, 36 | 37 | [Parameter()] 38 | [ValidateNotNullOrEmpty()] 39 | [System.String] 40 | $TypePrefix = 'digitalocean' 41 | ) 42 | begin { 43 | try { 44 | #region Turn down strict mode so that we can use JSON data without validating member existence first. 45 | 46 | Set-StrictMode -Version 1 47 | 48 | #endregion 49 | } catch { 50 | $PSCmdlet.ThrowTerminatingError($_) 51 | } 52 | } 53 | process { 54 | try { 55 | foreach ($item in $InputObject) { 56 | foreach ($propertyItem in $item.$Property) { 57 | #region If the property is a PSCustomObject, add type information to it. 58 | 59 | if ($propertyItem -is [System.Management.Automation.PSCustomObject]) { 60 | #region Identify the type name by combining the prefix and the property. 61 | 62 | $typeName = "${TypePrefix}.$($Property -replace '_|s$')" 63 | 64 | #endregion 65 | 66 | #region Convert nested properties as well if they are arrays or of type PSCustomObject. 67 | 68 | foreach ($member in $propertyItem.PSObject.Properties) { 69 | if ($member.TypeNameOfValue -eq 'System.Object[]') { 70 | $propertyItem.$($member.Name) = @(ConvertTo-DoPxObject -InputObject $propertyItem -Property $member.Name -TypePrefix $typeName) 71 | } else { #if ($property.TypeNameOfValue -eq 'System.Management.Automation.PSCustomObject') { 72 | $propertyItem.$($member.Name) = ConvertTo-DoPxObject -InputObject $propertyItem -Property $member.Name -TypePrefix $typeName 73 | } 74 | } 75 | 76 | #endregion 77 | 78 | #region Set the type information that is desired for all PSCustomObjects. 79 | 80 | $propertyItem.PSTypeNames.Clear() 81 | Add-Member -InputObject $propertyItem -TypeName 'digitalocean.object' 82 | if (@('digitalocean.backup','digitalocean.snapshot') -contains $typeName) { 83 | Add-Member -InputObject $propertyItem -TypeName 'digitalocean.image' 84 | } 85 | Add-Member -InputObject $propertyItem -TypeName $typeName 86 | 87 | #endregion 88 | } 89 | 90 | #endregion 91 | 92 | #region If the property is a string in datetime format, convert it and return it to the caller. 93 | 94 | if (($propertyItem -is [System.String]) -and 95 | ($propertyItem -match '^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$')) { 96 | $propertyItem = $propertyItem -as [System.DateTime] 97 | } 98 | 99 | #endregion 100 | 101 | #region Return the property value back to the caller. 102 | 103 | $propertyItem 104 | 105 | #endregion 106 | } 107 | } 108 | } catch { 109 | $PSCmdlet.ThrowTerminatingError($_) 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /functions/Copy-DoPxSnapshot.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Copies a snapshot in your DigitalOcean environment to a different region. 26 | .DESCRIPTION 27 | The Copy-DoPxSnapshot command copies a snapshot in your DigitalOcean environment to a different region. 28 | .INPUTS 29 | digitalocean.snapshot 30 | .OUTPUTS 31 | digitalocean.action,digitalocean.image 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Copy-DoPxSnapshot -Id 7606405 -RegionId nyc3 38 | 39 | This command copies snapshot id 7606405 to region "nyc3". 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxSnapshot | Copy-DoPxSnapshot -RegionId nyc3 44 | 45 | This command copies all snapshots in your DigitalOcean environment to region "nyc3". 46 | .LINK 47 | Get-DoPxSnapshot 48 | .LINK 49 | New-DoPxSnapshot 50 | .LINK 51 | Remove-DoPxSnapshot 52 | .LINK 53 | Rename-DoPxSnapshot 54 | .LINK 55 | Restore-DoPxSnapshot 56 | #> 57 | function Copy-DoPxSnapshot { 58 | [CmdletBinding(SupportsShouldProcess=$true)] 59 | [OutputType('digitalocean.action')] 60 | [OutputType('digitalocean.image')] 61 | param( 62 | # The numeric id of one or more snapshots. 63 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 64 | [ValidateNotNull()] 65 | [ValidateRange(1,[System.Int32]::MaxValue)] 66 | [System.Int32[]] 67 | $Id, 68 | 69 | # The region to which those snapshots will be copied. 70 | [Parameter(Position=1, Mandatory=$true)] 71 | [ValidateNotNullOrEmpty()] 72 | [System.String] 73 | $RegionId, 74 | 75 | # The access token for your DigitalOcean environment, in secure string format. 76 | [Parameter()] 77 | [ValidateNotNull()] 78 | [System.Security.SecureString] 79 | $AccessToken, 80 | 81 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 82 | [Parameter()] 83 | [System.Management.Automation.SwitchParameter] 84 | $Wait 85 | ) 86 | process { 87 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 88 | CommandName = 'Invoke-DoPxObjectAction' 89 | CommandType = 'Function' 90 | PreProcessScriptBlock = { 91 | #region Replace the RegionId bound parameter with a parameter hashtable for the action. 92 | 93 | $PSCmdlet.MyInvocation.BoundParameters['Parameter'] = @{region=$RegionId} 94 | $PSCmdlet.MyInvocation.BoundParameters.Remove('RegionId') > $null 95 | 96 | #endregion 97 | 98 | #region Add additional required parameters to the BoundParameters hashtable. 99 | 100 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'transfer' 101 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'images' 102 | 103 | #endregion 104 | } 105 | } 106 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 107 | Invoke-Snippet -Name ProxyFunction.End 108 | } 109 | } 110 | 111 | Export-ModuleMember -Function Copy-DoPxSnapshot -------------------------------------------------------------------------------- /functions/Get-DoPxDroplet.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the droplets that are available in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Get-DoPxDroplet command gets the droplets that are available in your DigitalOcean environment. 28 | 29 | Without the Id parameter, Get-DoPxDroplet gets all of the droplets that are available in your DigitalOcean environment. You can also use Get-DoPxDroplet command to get specific droplets by passing the droplet IDs to the Id parameter. 30 | .PARAMETER First 31 | Get only the specified number of droplets. 32 | .PARAMETER Skip 33 | Skip the specified number of droplets. If this parameter is used in conjunction with the First parameter, the specified number of droplets will be skipped before the paging support starts counting the first droplets to return. 34 | .PARAMETER IncludeTotalCount 35 | Return the total count of droplets that will be returned before returning the droplets themselves. 36 | .INPUTS 37 | None 38 | .OUTPUTS 39 | digitalocean.droplet 40 | .NOTES 41 | This command sends an HTTP GET request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 42 | .EXAMPLE 43 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 44 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 45 | PS C:\> Get-DoPxDroplet 46 | 47 | This command gets all droplets from the DigitalOcean account identified by the access token that is provided. 48 | .EXAMPLE 49 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 50 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 51 | PS C:\> Get-DoPxDroplet -Id 4849480 52 | 53 | This command gets the droplet with id 4849480 from the DigitalOcean account identified by the access token that is provided. 54 | .LINK 55 | Disable-DoPxDropletOption 56 | .LINK 57 | Enable-DoPxDropletOption 58 | .LINK 59 | Get-DoPxBackup 60 | .LINK 61 | Get-DoPxKernel 62 | .LINK 63 | Get-DoPxSnapshot 64 | .LINK 65 | New-DoPxDroplet 66 | .LINK 67 | Remove-DoPxDroplet 68 | .LINK 69 | Rename-DoPxDroplet 70 | .LINK 71 | Reset-DoPxDroplet 72 | .LINK 73 | Resize-DoPxDroplet 74 | .LINK 75 | Restart-DoPxDroplet 76 | .LINK 77 | Start-DoPxDroplet 78 | .LINK 79 | Stop-DoPxDroplet 80 | #> 81 | function Get-DoPxDroplet { 82 | [CmdletBinding(SupportsPaging=$true)] 83 | [OutputType('digitalocean.droplet')] 84 | param( 85 | # The numeric id of the droplet. 86 | [Parameter(Position=0)] 87 | [ValidateNotNull()] 88 | [ValidateRange(1,[System.Int32]::MaxValue)] 89 | [System.Int32[]] 90 | $Id, 91 | 92 | # The access token for your DigitalOcean account, in secure string format. 93 | [Parameter()] 94 | [ValidateNotNull()] 95 | [System.Security.SecureString] 96 | $AccessToken 97 | ) 98 | begin { 99 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 100 | CommandName = 'Get-DoPxObject' 101 | CommandType = 'Function' 102 | PreProcessScriptBlock = { 103 | #region Add additional required parameters to the BoundParameters hashtable. 104 | 105 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 106 | 107 | #endregion 108 | } 109 | } 110 | } 111 | process { 112 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 113 | } 114 | end { 115 | Invoke-Snippet -Name ProxyFunction.End 116 | } 117 | } 118 | 119 | Export-ModuleMember -Function Get-DoPxDroplet -------------------------------------------------------------------------------- /helpers/Remove-DoPxObject.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | function Remove-DoPxObject { 24 | [CmdletBinding(SupportsShouldProcess=$true)] 25 | [OutputType([System.Void])] 26 | param( 27 | [Parameter(Position=0, Mandatory=$true)] 28 | [ValidateNotNullOrEmpty()] 29 | [System.String] 30 | $RelativeUri, 31 | 32 | [Parameter(Position=1, Mandatory=$true)] 33 | [ValidateNotNullOrEmpty()] 34 | [System.String[]] 35 | $Id, 36 | 37 | [Parameter(Position=2)] 38 | [ValidateNotNullOrEmpty()] 39 | [System.String] 40 | $RelatedObjectUri, 41 | 42 | [Parameter(Position=3)] 43 | [ValidateNotNullOrEmpty()] 44 | [System.String[]] 45 | $RelatedObjectId, 46 | 47 | [Parameter()] 48 | [ValidateNotNull()] 49 | [System.Security.SecureString] 50 | $AccessToken 51 | ) 52 | try { 53 | #region If RelatedObjectId is used without the Id parameter, raise an error. 54 | 55 | $PSCmdlet.ValidateParameterDependency('RelatedObjectUri','Id') 56 | 57 | #endregion 58 | 59 | #region If RelatedObjectId is used without the RelatedObjectUri parameter, raise an error. 60 | 61 | $PSCmdlet.ValidateParameterDependency('RelatedObjectId','RelatedObjectUri') 62 | 63 | #endregion 64 | 65 | #region Identify the passthru ShouldProcess parameters. 66 | 67 | $shouldProcessParameters = $PSCmdlet.GetBoundShouldProcessParameters() 68 | 69 | #endregion 70 | 71 | #region Add the relative uri with the endpoint prefix. 72 | 73 | $uri = "${script:DigitalOceanEndpointUri}/$($RelativeUri -replace '^/+|/+$')" 74 | 75 | #endregion 76 | 77 | #region Prefix the Uri parameters with a slash if not present. 78 | 79 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Id')) { 80 | $internalId = '' -as [System.String[]] 81 | } else { 82 | $internalId = $Id -replace '^([^/])','/$1' -as $Id.GetType() 83 | } 84 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('RelatedObjectUri')) { 85 | $internalRelatedObjectUri = '' -as [System.String] 86 | } else { 87 | $internalRelatedObjectUri = $RelatedObjectUri -replace '^([^/])','/$1' -as $RelatedObjectUri.GetType() 88 | } 89 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('RelatedObjectId')) { 90 | $internalRelatedObjectId = '' -as [System.String[]] 91 | } else { 92 | $internalRelatedObjectId = $RelatedObjectId -replace '^([^/])','/$1' -as $RelatedObjectId.GetType() 93 | } 94 | 95 | #endregion 96 | 97 | #region Initialize the web request headers. 98 | 99 | $accessTokenParameter = $PSCmdlet.GetSplattableParameters('AccessToken') 100 | $headers = Get-DoPxWebRequestHeader @accessTokenParameter 101 | 102 | #endregion 103 | 104 | foreach ($item in $internalId) { 105 | foreach ($relatedItem in $internalRelatedObjectId) { 106 | #region Construct the Uri according to the parameter values used in this iteration. 107 | 108 | $endpointUri = $uri 109 | if ($item) { 110 | $endpointUri += $item 111 | } 112 | if ($internalRelatedObjectUri) { 113 | $endpointUri += "${internalRelatedObjectUri}${relatedItem}" 114 | } 115 | 116 | #endregion 117 | 118 | #region Invoke the web request. 119 | 120 | Invoke-DoPxWebRequest -Uri $endpointUri -Method Delete -Headers $headers @shouldProcessParameters 121 | 122 | #endregion 123 | } 124 | } 125 | } catch { 126 | $PSCmdlet.ThrowTerminatingError($_) 127 | } 128 | } 129 | 130 | Export-ModuleMember -Function Remove-DoPxObject -------------------------------------------------------------------------------- /functions/New-DoPxSnapshot.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Creates a new snapshot for a droplet that is available in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The New-DoPxSnapshot command creates a new snapshot for a droplet that is available in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.image 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> New-DoPxSnapshot -DropletId 4849480 -Name 'Before kernel upgrade' 38 | 39 | This command creates a new snapshot called "Before kernel upgrade" for the droplet with id 4849480. 40 | .LINK 41 | Copy-DoPxSnapshot 42 | .LINK 43 | Get-DoPxSnapshot 44 | .LINK 45 | Remove-DoPxSnapshot 46 | .LINK 47 | Rename-DoPxSnapshot 48 | .LINK 49 | Restore-DoPxSnapshot 50 | #> 51 | function New-DoPxSnapshot { 52 | [CmdletBinding(SupportsShouldProcess=$true)] 53 | [OutputType('digitalocean.action')] 54 | [OutputType('digitalocean.snapshot')] 55 | param( 56 | # The numeric id of the droplet. 57 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 58 | [ValidateNotNull()] 59 | [ValidateRange(1,[System.Int32]::MaxValue)] 60 | [Alias('Id')] 61 | [System.Int32[]] 62 | $DropletId, 63 | 64 | # The name you want to give to the droplet snapshot. 65 | [Parameter(Position=1, ValueFromPipelineByPropertyName=$true)] 66 | [ValidateNotNullOrEmpty()] 67 | [System.String] 68 | $Name, 69 | 70 | # The access token for your DigitalOcean account, in secure string format. 71 | [Parameter()] 72 | [ValidateNotNull()] 73 | [System.Security.SecureString] 74 | $AccessToken, 75 | 76 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 77 | [Parameter()] 78 | [System.Management.Automation.SwitchParameter] 79 | $Wait 80 | ) 81 | process { 82 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 83 | CommandName = 'Invoke-DoPxObjectAction' 84 | CommandType = 'Function' 85 | PreProcessScriptBlock = { 86 | #region Move the id from the DropletId parameter to the Id parameter. 87 | 88 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DropletId 89 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DropletId') > $null 90 | 91 | #endregion 92 | 93 | #region Replace the Name bound parameter with a parameter hashtable for the action. 94 | 95 | if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Name')) { 96 | $PSCmdlet.MyInvocation.BoundParameters['Parameter'] = @{name=$Name} 97 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Name') > $null 98 | } 99 | 100 | #endregion 101 | 102 | #region Add additional required parameters to the BoundParameters hashtable. 103 | 104 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'snapshot' 105 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 106 | 107 | #endregion 108 | } 109 | } 110 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 111 | Invoke-Snippet -Name ProxyFunction.End 112 | } 113 | } 114 | 115 | Export-ModuleMember -Function New-DoPxSnapshot -------------------------------------------------------------------------------- /functions/Disable-DoPxDropletOption.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Disables automatic backup on a droplet in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Disable-DoPxDropletOption command disables automatic backup on a droplet in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Disable-DoPxDropletOption -DropletId 4849480 -AutomaticBackup 38 | 39 | This command disables automatic backup on the droplet with id 4849480. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxDroplet | Disable-DoPxDropletOption -AutomaticBackup 44 | 45 | This command disables automatic backup on all droplets in your DigitalOcean environment. 46 | .LINK 47 | Enable-DoPxDropletOption 48 | .LINK 49 | Get-DoPxDroplet 50 | #> 51 | function Disable-DoPxDropletOption { 52 | [CmdletBinding(SupportsShouldProcess=$true)] 53 | [OutputType('digitalocean.action')] 54 | [OutputType('digitalocean.droplet')] 55 | param( 56 | # The numeric id of one or more droplets with options that you want to enable. 57 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 58 | [ValidateNotNull()] 59 | [ValidateRange(1,[System.Int32]::MaxValue)] 60 | [Alias('Id')] 61 | [System.Int32[]] 62 | $DropletId, 63 | 64 | # Disables automatic backup of the droplet. 65 | [Parameter(Mandatory=$true)] 66 | [ValidateScript({ 67 | if (-not $_.IsPresent) { 68 | throw 'Passing false into the AutomaticBackup parameter is not supported.' 69 | } 70 | $true 71 | })] 72 | [System.Management.Automation.SwitchParameter] 73 | $AutomaticBackup, 74 | 75 | # The access token for your DigitalOcean account, in secure string format. 76 | [Parameter()] 77 | [ValidateNotNull()] 78 | [System.Security.SecureString] 79 | $AccessToken, 80 | 81 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 82 | [Parameter()] 83 | [System.Management.Automation.SwitchParameter] 84 | $Wait 85 | ) 86 | process { 87 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 88 | CommandName = 'Invoke-DoPxObjectAction' 89 | CommandType = 'Function' 90 | PreProcessScriptBlock = { 91 | #region Replace the DropletId parameter with the Id parameter. 92 | 93 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DropletId 94 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DropletId') > $null 95 | 96 | #endregion 97 | 98 | #region Add additional required parameters to the BoundParameters hashtable. 99 | 100 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'disable_backups' 101 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 102 | 103 | #endregion 104 | } 105 | } 106 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 107 | Invoke-Snippet -Name ProxyFunction.End 108 | } 109 | } 110 | 111 | Export-ModuleMember -Function Disable-DoPxDropletOption -------------------------------------------------------------------------------- /functions/Remove-DoPxSshKey.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Removes one or more ssh keys that have been added to your DigitalOcean account. 26 | .DESCRIPTION 27 | The Remove-DoPxSshKey command removes one or more ssh keys that have been added to your DigitalOcean account. 28 | 29 | You can use Remove-DoPxSshKey command to remove specific ssh keys by passing the ssh key IDs to the Id parameter or fingerprints to the Fingerprint parameter. 30 | .INPUTS 31 | digitalocean.sshkey 32 | .OUTPUTS 33 | None 34 | .NOTES 35 | This command sends an HTTP DELETE request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 36 | .EXAMPLE 37 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 38 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 39 | PS C:\> Remove-DoPxSshKey -Id 542108 40 | 41 | This command removes the ssh key with id 542108 from your DigitalOcean account. 42 | .EXAMPLE 43 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 44 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 45 | PS C:\> Remove-DoPxSshKey -Fingerprint 0b:87:45:bd:f0:bf:c9:26:fc:79:1c:ea:d2:a3:e5:36 46 | 47 | This command removes the ssh key that has the fingerprint '0b:87:45:bd:f0:bf:c9:26:fc:79:1c:ea:d2:a3:e5:36' from your DigitalOcean account. 48 | .EXAMPLE 49 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 50 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 51 | PS C:\> Get-DoPxSshKey | Remove-DoPxSshKey 52 | 53 | This command removes all ssh keys from your DigitalOcean account. 54 | .LINK 55 | Add-DoPxSshKey 56 | .LINK 57 | Get-DoPxSshKey 58 | .LINK 59 | Rename-DoPxSshKey 60 | #> 61 | function Remove-DoPxSshKey { 62 | [CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName='Id')] 63 | [OutputType([System.Void])] 64 | param( 65 | # The numeric id of the ssh key. 66 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true, ParameterSetName='Id')] 67 | [ValidateNotNull()] 68 | [ValidateRange(1,[System.Int32]::MaxValue)] 69 | [System.Int32[]] 70 | $Id, 71 | 72 | # The fingerprint of the ssh key. 73 | [Parameter(Position=0, Mandatory=$true, ParameterSetName='Fingerprint')] 74 | [ValidateNotNullOrEmpty()] 75 | [System.String[]] 76 | $Fingerprint, 77 | 78 | # The access token for your DigitalOcean account, in secure string format. 79 | [Parameter()] 80 | [ValidateNotNull()] 81 | [System.Security.SecureString] 82 | $AccessToken 83 | ) 84 | process { 85 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 86 | CommandName = 'Remove-DoPxObject' 87 | CommandType = 'Function' 88 | PreProcessScriptBlock = { 89 | #region Set up the ID properly if a fingerprint is being used in the search. 90 | 91 | if ($PSCmdlet.ParameterSetName -eq 'Fingerprint') { 92 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $Fingerprint 93 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Fingerprint') > $null 94 | } 95 | 96 | #endregion 97 | 98 | #region Add additional required parameters to the BoundParameters hashtable. 99 | 100 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'account/keys' 101 | 102 | #endregion 103 | } 104 | } 105 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 106 | Invoke-Snippet -Name ProxyFunction.End 107 | } 108 | } 109 | 110 | Export-ModuleMember -Function Remove-DoPxSshKey -------------------------------------------------------------------------------- /functions/Restore-DoPxBackup.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Restores a backup to a droplet that is available in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Restore-DoPxBackup command restores a backup to a droplet that is available in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.backup 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Restore-DoPxBackup -Id 9802541 -DropletId 4849480 38 | 39 | This command restores the backup with id 9802541 to the droplet with id 4849480. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> $dropletId = 4849480 44 | PS C:\> Get-DoPxBackup -DropletId $dropletId | Where-Object {$_.Name -eq 'Version 1.1'} | Restore-DoPxBackup -DropletId $dropletId 45 | 46 | This command restores a backup named "Version 1.1" to the droplet with id 4849480. 47 | .LINK 48 | Copy-DoPxBackup 49 | .LINK 50 | Get-DoPxBackup 51 | .LINK 52 | Remove-DoPxBackup 53 | .LINK 54 | Rename-DoPxBackup 55 | #> 56 | function Restore-DoPxBackup { 57 | [CmdletBinding(SupportsShouldProcess=$true)] 58 | [OutputType('digitalocean.action')] 59 | [OutputType('digitalocean.droplet')] 60 | param( 61 | # The numeric id of the backup being restored. 62 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 63 | [ValidateNotNull()] 64 | [ValidateRange(1,[System.Int32]::MaxValue)] 65 | [System.Int32] 66 | $Id, 67 | 68 | # The id of droplet where the backup will be restored. 69 | [Parameter(Position=1, Mandatory=$true)] 70 | [ValidateNotNull()] 71 | [ValidateRange(1,[System.Int32]::MaxValue)] 72 | [System.Int32] 73 | $DropletId, 74 | 75 | # The access token for your DigitalOcean account, in secure string format. 76 | [Parameter()] 77 | [ValidateNotNull()] 78 | [System.Security.SecureString] 79 | $AccessToken, 80 | 81 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 82 | [Parameter()] 83 | [System.Management.Automation.SwitchParameter] 84 | $Wait 85 | ) 86 | process { 87 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 88 | CommandName = 'Invoke-DoPxObjectAction' 89 | CommandType = 'Function' 90 | PreProcessScriptBlock = { 91 | #region Replace the Id bound parameter with the droplet ID and build a parameter hashtable for the action. 92 | 93 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DropletId 94 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DropletId') > $null 95 | $PSCmdlet.MyInvocation.BoundParameters['Parameter'] = @{image=$Id} 96 | 97 | #endregion 98 | 99 | #region Add additional required parameters to the BoundParameters hashtable. 100 | 101 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'restore' 102 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 103 | 104 | #endregion 105 | } 106 | } 107 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 108 | Invoke-Snippet -Name ProxyFunction.End 109 | } 110 | } 111 | 112 | Export-ModuleMember -Function Restore-DoPxBackup -------------------------------------------------------------------------------- /functions/Restore-DoPxSnapshot.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Restores a snapshot that was previously taken to a droplet in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Restore-DoPxSnapshot command restores a snapshot that was previously taken to a droplet in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.snapshot 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Restore-DoPxSnapshot -Id 7606405 -DropletId 4849480 38 | 39 | This command restores snapshot 7606405 to the droplet with id 4849480. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> $dropletId = 4849480 44 | PS C:\> Get-DoPxSnapshot -DropletId $dropletId | Where-Object {$_.Name -eq 'Pre-kernel upgrade'} | Restore-DoPxSnapshot -DropletId $dropletId 45 | 46 | This command restores a snapshot named "Pre-kernel upgrade" to the droplet with id 4849480. 47 | .LINK 48 | Copy-DoPxSnapshot 49 | .LINK 50 | Get-DoPxSnapshot 51 | .LINK 52 | New-DoPxSnapshot 53 | .LINK 54 | Remove-DoPxSnapshot 55 | .LINK 56 | Rename-DoPxSnapshot 57 | #> 58 | function Restore-DoPxSnapshot { 59 | [CmdletBinding(SupportsShouldProcess=$true)] 60 | [OutputType('digitalocean.action')] 61 | [OutputType('digitalocean.droplet')] 62 | param( 63 | # The numeric id of the snapshot that you want to restore to a droplet. 64 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 65 | [ValidateNotNull()] 66 | [ValidateRange(1,[System.Int32]::MaxValue)] 67 | [System.Int32] 68 | $Id, 69 | 70 | # The numeric id of the droplet where the snapshot will be restored. 71 | [Parameter(Position=1, Mandatory=$true)] 72 | [ValidateNotNull()] 73 | [ValidateRange(1,[System.Int32]::MaxValue)] 74 | [System.Int32] 75 | $DropletId, 76 | 77 | # The access token for your DigitalOcean account, in secure string format. 78 | [Parameter()] 79 | [ValidateNotNull()] 80 | [System.Security.SecureString] 81 | $AccessToken, 82 | 83 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 84 | [Parameter()] 85 | [System.Management.Automation.SwitchParameter] 86 | $Wait 87 | ) 88 | process { 89 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 90 | CommandName = 'Invoke-DoPxObjectAction' 91 | CommandType = 'Function' 92 | PreProcessScriptBlock = { 93 | #region Replace the Id bound parameter with the droplet ID and build a parameter hashtable for the action. 94 | 95 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DropletId 96 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DropletId') > $null 97 | $PSCmdlet.MyInvocation.BoundParameters['Parameter'] = @{image=$Id} 98 | 99 | #endregion 100 | 101 | #region Add additional required parameters to the BoundParameters hashtable. 102 | 103 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'rebuild' 104 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 105 | 106 | #endregion 107 | } 108 | } 109 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 110 | Invoke-Snippet -Name ProxyFunction.End 111 | } 112 | } 113 | 114 | Export-ModuleMember -Function Restore-DoPxSnapshot -------------------------------------------------------------------------------- /functions/Rename-DoPxDroplet.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Renames a droplet that is available in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Rename-DoPxDroplet command renames a droplet that is available in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | digitalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Rename-DoPxDroplet -Id 4849480 -NewName RailsServer 38 | 39 | This command sets the name of the droplet with id 4849480 to "RailsServer". 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxDroplet | Rename-DoPxDroplet -NewName {$_.name + '.Personal'} 44 | 45 | This command appends ".Personal" to the name of every droplet in your DigitalOcean environment. 46 | .LINK 47 | Disable-DoPxDropletOption 48 | .LINK 49 | Enable-DoPxDropletOption 50 | .LINK 51 | Get-DoPxBackup 52 | .LINK 53 | Get-DoPxDroplet 54 | .LINK 55 | Get-DoPxKernel 56 | .LINK 57 | Get-DoPxSnapshot 58 | .LINK 59 | New-DoPxDroplet 60 | .LINK 61 | Remove-DoPxDroplet 62 | .LINK 63 | Reset-DoPxDroplet 64 | .LINK 65 | Resize-DoPxDroplet 66 | .LINK 67 | Restart-DoPxDroplet 68 | .LINK 69 | Start-DoPxDroplet 70 | .LINK 71 | Stop-DoPxDroplet 72 | #> 73 | function Rename-DoPxDroplet { 74 | [CmdletBinding(SupportsShouldProcess=$true)] 75 | [OutputType('digitalocean.action')] 76 | [OutputType('digitalocean.droplet')] 77 | param( 78 | # The numeric id of the droplet. 79 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 80 | [ValidateNotNull()] 81 | [ValidateRange(1,[System.Int32]::MaxValue)] 82 | [System.Int32] 83 | $Id, 84 | 85 | # The new name of the droplet. 86 | [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 87 | [ValidateNotNullOrEmpty()] 88 | [System.String] 89 | $NewName, 90 | 91 | # The access token for your DigitalOcean environment, in secure string format. 92 | [Parameter()] 93 | [ValidateNotNull()] 94 | [System.Security.SecureString] 95 | $AccessToken, 96 | 97 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 98 | [Parameter()] 99 | [System.Management.Automation.SwitchParameter] 100 | $Wait 101 | ) 102 | process { 103 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 104 | CommandName = 'Invoke-DoPxObjectAction' 105 | CommandType = 'Function' 106 | PreProcessScriptBlock = { 107 | #region Replace the NewName bound parameter with a parameter hashtable for the action. 108 | 109 | $PSCmdlet.MyInvocation.BoundParameters['Parameter'] = @{name=$NewName} 110 | $PSCmdlet.MyInvocation.BoundParameters.Remove('NewName') > $null 111 | 112 | #endregion 113 | 114 | #region Add additional required parameters to the BoundParameters hashtable. 115 | 116 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'rename' 117 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 118 | 119 | #endregion 120 | } 121 | } 122 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 123 | Invoke-Snippet -Name ProxyFunction.End 124 | } 125 | } 126 | 127 | Export-ModuleMember -Function Rename-DoPxDroplet -------------------------------------------------------------------------------- /functions/Update-DoPxKernel.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Changes the kernel that is installed in a droplet in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Update-DoPxKernel command changes the kernel that is installed in a droplet in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Update-DoPxKernel -Id 4849480 -KernelId 1258 38 | 39 | This command installs the kernel with id 1258 in droplet with id 4849480. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxDroplet | Update-DoPxKernel -KernelId 1258 44 | 45 | This command installs the kernel with id 1258 in all droplets in your DigitalOcean environment. 46 | .LINK 47 | Get-DoPxDroplet 48 | .LINK 49 | Get-DoPxKernel 50 | #> 51 | function Update-DoPxKernel { 52 | [CmdletBinding(SupportsShouldProcess=$true)] 53 | [OutputType('digitalocean.action')] 54 | [OutputType('digitalocean.droplet')] 55 | param( 56 | # The numeric id of the droplet. 57 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 58 | [ValidateNotNullOrEmpty()] 59 | [ValidateRange(1,[System.Int32]::MaxValue)] 60 | [Alias('Id')] 61 | [System.Int32[]] 62 | $DropletId, 63 | 64 | # The numeric id of the kernel that you want to use in your droplet. Use Get-DoPxKernel to get a list of the kernels that are available to a droplet. 65 | [Parameter(Position=1, Mandatory=$true)] 66 | [ValidateNotNull()] 67 | [ValidateRange(1,[System.Int32]::MaxValue)] 68 | [System.Int32] 69 | $KernelId, 70 | 71 | # The access token for your DigitalOcean account, in secure string format. 72 | [Parameter()] 73 | [ValidateNotNull()] 74 | [System.Security.SecureString] 75 | $AccessToken, 76 | 77 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 78 | [Parameter()] 79 | [System.Management.Automation.SwitchParameter] 80 | $Wait 81 | ) 82 | process { 83 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 84 | CommandName = 'Invoke-DoPxObjectAction' 85 | CommandType = 'Function' 86 | PreProcessScriptBlock = { 87 | #region Replace the DropletId bound parameter with the Id parameter. 88 | 89 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DropletId 90 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DropletId') > $null 91 | 92 | #endregion 93 | 94 | #region Replace the KernelId bound parameter with a parameter hashtable for the action. 95 | 96 | $PSCmdlet.MyInvocation.BoundParameters['Parameter'] = @{kernel=$KernelId} 97 | $PSCmdlet.MyInvocation.BoundParameters.Remove('KernelId') > $null 98 | 99 | #endregion 100 | 101 | #region Add additional required parameters to the BoundParameters hashtable. 102 | 103 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'change_kernel' 104 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 105 | 106 | #endregion 107 | } 108 | } 109 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 110 | Invoke-Snippet -Name ProxyFunction.End 111 | } 112 | } 113 | 114 | Export-ModuleMember -Function Update-DoPxKernel -------------------------------------------------------------------------------- /functions/Resize-DoPxDroplet.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Changes the size configuration for a droplet in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Resize-DoPxDroplet command changes the size configuration for a droplet in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Resize-DoPxDroplet -Id 4849480 -NewSizeId 4gb 38 | 39 | This command applies the 4gb size configuration to the droplet with id 4849480. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxDroplet | Resize-DoPxDroplet -NewSizeId 4gb 44 | 45 | This command applies the 4gb size configuration to all droplets. 46 | .LINK 47 | Disable-DoPxDropletOption 48 | .LINK 49 | Enable-DoPxDropletOption 50 | .LINK 51 | Get-DoPxBackup 52 | .LINK 53 | Get-DoPxDroplet 54 | .LINK 55 | Get-DoPxKernel 56 | .LINK 57 | Get-DoPxSnapshot 58 | .LINK 59 | New-DoPxDroplet 60 | .LINK 61 | Remove-DoPxDroplet 62 | .LINK 63 | Rename-DoPxDroplet 64 | .LINK 65 | Reset-DoPxDroplet 66 | .LINK 67 | Restart-DoPxDroplet 68 | .LINK 69 | Start-DoPxDroplet 70 | .LINK 71 | Stop-DoPxDroplet 72 | #> 73 | function Resize-DoPxDroplet { 74 | [CmdletBinding(SupportsShouldProcess=$true)] 75 | [OutputType('digitalocean.action')] 76 | [OutputType('digitalocean.droplet')] 77 | param( 78 | # The numeric id of the droplet. 79 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 80 | [ValidateNotNull()] 81 | [ValidateRange(1,[System.Int32]::MaxValue)] 82 | [System.Int32[]] 83 | $Id, 84 | 85 | # The id for the size configuration that will be used when creating the droplet. Consult your region settings to see which size configurations are supported. 86 | [Parameter(Position=2, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 87 | [ValidateNotNullOrEmpty()] 88 | [System.String] 89 | $NewSizeId, 90 | 91 | # The access token for your DigitalOcean account, in secure string format. 92 | [Parameter()] 93 | [ValidateNotNull()] 94 | [System.Security.SecureString] 95 | $AccessToken, 96 | 97 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 98 | [Parameter()] 99 | [System.Management.Automation.SwitchParameter] 100 | $Wait 101 | ) 102 | process { 103 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 104 | CommandName = 'Invoke-DoPxObjectAction' 105 | CommandType = 'Function' 106 | PreProcessScriptBlock = { 107 | #region Replace the NewSizeId bound parameter with a parameter hashtable for the action. 108 | 109 | $PSCmdlet.MyInvocation.BoundParameters['Parameter'] = @{size=$NewSizeId} 110 | $PSCmdlet.MyInvocation.BoundParameters.Remove('NewSizeId') > $null 111 | 112 | #endregion 113 | 114 | #region Add additional required parameters to the BoundParameters hashtable. 115 | 116 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'resize' 117 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 118 | 119 | #endregion 120 | } 121 | } 122 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 123 | Invoke-Snippet -Name ProxyFunction.End 124 | } 125 | } 126 | 127 | Export-ModuleMember -Function Resize-DoPxDroplet -------------------------------------------------------------------------------- /helpers/Set-DoPxObject.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | function Set-DoPxObject { 24 | [CmdletBinding(SupportsShouldProcess=$true)] 25 | [OutputType('digitalocean.object')] 26 | param( 27 | [Parameter(Position=0, Mandatory=$true)] 28 | [ValidateNotNullOrEmpty()] 29 | [System.String] 30 | $RelativeUri, 31 | 32 | [Parameter(Position=1, Mandatory=$true)] 33 | [ValidateNotNullOrEmpty()] 34 | [System.String[]] 35 | $Id, 36 | 37 | [Parameter(Position=2)] 38 | [ValidateNotNullOrEmpty()] 39 | [System.String] 40 | $RelatedObjectUri, 41 | 42 | [Parameter(Position=3)] 43 | [ValidateNotNullOrEmpty()] 44 | [System.String[]] 45 | $RelatedObjectId, 46 | 47 | [Parameter(Mandatory=$true)] 48 | [ValidateNotNullOrEmpty()] 49 | [Alias('PropertyValues')] 50 | [System.Collections.Hashtable] 51 | $Property, 52 | 53 | [Parameter()] 54 | [ValidateNotNull()] 55 | [System.Security.SecureString] 56 | $AccessToken, 57 | 58 | [Parameter()] 59 | [System.Management.Automation.SwitchParameter] 60 | $PassThru 61 | ) 62 | try { 63 | #region If RelatedObjectId is used without the Id parameter, raise an error. 64 | 65 | $PSCmdlet.ValidateParameterDependency('RelatedObjectUri','Id') 66 | 67 | #endregion 68 | 69 | #region If RelatedObjectId is used without the RelatedObjectUri parameter, raise an error. 70 | 71 | $PSCmdlet.ValidateParameterDependency('RelatedObjectId','RelatedObjectUri') 72 | 73 | #endregion 74 | 75 | #region Identify the passthru ShouldProcess parameters. 76 | 77 | $shouldProcessParameters = $PSCmdlet.GetBoundShouldProcessParameters() 78 | 79 | #endregion 80 | 81 | #region Add the relative uri with the endpoint prefix. 82 | 83 | $uri = "${script:DigitalOceanEndpointUri}/$($RelativeUri -replace '^/+|/+$')" 84 | 85 | #endregion 86 | 87 | #region Prefix the Uri parameters with a slash if not present. 88 | 89 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Id')) { 90 | $internalId = '' -as [System.String[]] 91 | } else { 92 | $internalId = $Id -replace '^([^/])','/$1' -as $Id.GetType() 93 | } 94 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('RelatedObjectUri')) { 95 | $internalRelatedObjectUri = '' -as [System.String] 96 | } else { 97 | $internalRelatedObjectUri = $RelatedObjectUri -replace '^([^/])','/$1' -as $RelatedObjectUri.GetType() 98 | } 99 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('RelatedObjectId')) { 100 | $internalRelatedObjectId = '' -as [System.String[]] 101 | } else { 102 | $internalRelatedObjectId = $RelatedObjectId -replace '^([^/])','/$1' -as $RelatedObjectId.GetType() 103 | } 104 | 105 | #endregion 106 | 107 | #region Initialize the web request headers. 108 | 109 | $accessTokenParameter = $PSCmdlet.GetSplattableParameters('AccessToken') 110 | $headers = Get-DoPxWebRequestHeader @accessTokenParameter 111 | 112 | #endregion 113 | 114 | foreach ($item in $internalId) { 115 | foreach ($relatedItem in $internalRelatedObjectId) { 116 | #region Construct the Uri according to the parameter values used in this iteration. 117 | 118 | $endpointUri = $uri 119 | if ($item) { 120 | $endpointUri += $item 121 | } 122 | if ($internalRelatedObjectUri) { 123 | $endpointUri += "${internalRelatedObjectUri}${relatedItem}" 124 | } 125 | 126 | #endregion 127 | 128 | #region Invoke the web request. 129 | 130 | Invoke-DoPxWebRequest -Uri $endpointUri -Method Put -Headers $headers -Body $Property -PassThru:$($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('PassThru') -and $PassThru) @shouldProcessParameters 131 | 132 | #endregion 133 | } 134 | } 135 | } catch { 136 | $PSCmdlet.ThrowTerminatingError($_) 137 | } 138 | } 139 | 140 | Export-ModuleMember -Function Set-DoPxObject -------------------------------------------------------------------------------- /functions/Rename-DoPxSshKey.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Rename an ssh key that has been added to your DigitalOcean account. 26 | .DESCRIPTION 27 | The Rename-DoPxSshKey command renames an ssh key that has been added to your DigitalOcean account. 28 | 29 | You can use Rename-DoPxSshKey command to rename a specific ssh key by passing the ssh key ID to the Id parameter or fingerprint to the Fingerprint parameter. 30 | .INPUTS 31 | digitalocean.sshkey 32 | .OUTPUTS 33 | digitalocean.sshkey 34 | .NOTES 35 | This command sends an HTTP PUT request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 36 | .EXAMPLE 37 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 38 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 39 | PS C:\> Rename-DoPxSshKey -Id 542108 -NewName Personal 40 | 41 | This command sets the name for the ssh key with id 542108 to "Personal". 42 | .EXAMPLE 43 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 44 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 45 | PS C:\> Rename-DoPxSshKey -Fingerprint 0b:87:45:bd:f0:bf:c9:26:fc:79:1c:ea:d2:a3:e5:36 -NewName Personal 46 | 47 | This command sets the name for the ssh key that has the fingerprint '0b:87:45:bd:f0:bf:c9:26:fc:79:1c:ea:d2:a3:e5:36' to "Personal". 48 | .LINK 49 | Add-DoPxSshKey 50 | .LINK 51 | Get-DoPxSshKey 52 | .LINK 53 | Remove-DoPxSshKey 54 | #> 55 | function Rename-DoPxSshKey { 56 | [CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName='Id')] 57 | [OutputType('droplet.sshkey')] 58 | param( 59 | # The numeric id of the ssh key. 60 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true, ParameterSetName='Id')] 61 | [ValidateNotNull()] 62 | [ValidateRange(1,[System.Int32]::MaxValue)] 63 | [System.Int32] 64 | $Id, 65 | 66 | # The fingerprint of the ssh key. 67 | [Parameter(Position=0, Mandatory=$true, ParameterSetName='Fingerprint')] 68 | [ValidateNotNullOrEmpty()] 69 | [System.String] 70 | $Fingerprint, 71 | 72 | # The new name of the ssh key. 73 | [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 74 | [ValidateNotNullOrEmpty()] 75 | [System.String] 76 | $NewName, 77 | 78 | # The access token for your DigitalOcean account, in secure string format. 79 | [Parameter()] 80 | [ValidateNotNull()] 81 | [System.Security.SecureString] 82 | $AccessToken, 83 | 84 | # Returns the updated sshkey object to the pipeline. By default, this command does not return anything. 85 | [Parameter()] 86 | [System.Management.Automation.SwitchParameter] 87 | $PassThru 88 | ) 89 | process { 90 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 91 | CommandName = 'Set-DoPxObject' 92 | CommandType = 'Function' 93 | PreProcessScriptBlock = { 94 | #region Set up the ID properly if a fingerprint is being used in the search. 95 | 96 | if ($PSCmdlet.ParameterSetName -eq 'Fingerprint') { 97 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $Fingerprint 98 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Fingerprint') > $null 99 | } 100 | 101 | #endregion 102 | 103 | #region Replace the NewName bound parameter with a parameter hashtable for the action. 104 | 105 | $PSCmdlet.MyInvocation.BoundParameters['Property'] = @{name=$NewName} 106 | $PSCmdlet.MyInvocation.BoundParameters.Remove('NewName') > $null 107 | 108 | #endregion 109 | 110 | #region Add additional required parameters to the BoundParameters hashtable. 111 | 112 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'account/keys' 113 | 114 | #endregion 115 | } 116 | } 117 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 118 | Invoke-Snippet -Name ProxyFunction.End 119 | } 120 | } 121 | 122 | Export-ModuleMember -Function Rename-DoPxSshKey -------------------------------------------------------------------------------- /functions/Get-DoPxBackup.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the backups that have been created in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Get-DoPxBackup command gets the backups that have been created in your DigitalOcean environment. 28 | 29 | Without the DropletId parameter, Get-DoPxBackup gets all of the backups that are available in your DigitalOcean environment. You can also use the Get-DoPxBackup command to get backups for specific droplets by passing droplet IDs to the DropletId parameter. 30 | .PARAMETER First 31 | Get only the specified number of backups. 32 | .PARAMETER Skip 33 | Skip the specified number of backups. If this parameter is used in conjunction with the First parameter, the specified number of backups will be skipped before the paging support starts counting the first backup to return. 34 | .PARAMETER IncludeTotalCount 35 | Return the total count of backups that will be returned before returning the backups themselves. 36 | .INPUTS 37 | None 38 | .OUTPUTS 39 | digitalocean.backup 40 | .NOTES 41 | This command sends an HTTP GET request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 42 | .EXAMPLE 43 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 44 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 45 | PS C:\> Get-DoPxBackup 46 | 47 | This command gets all backups that have been created in your DigitalOcean environment. 48 | .EXAMPLE 49 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 50 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 51 | PS C:\> Get-DoPxBackup -DropletId 4849480 52 | 53 | This command gets all backups that have been created for the droplet with id 4849480 in your DigitalOcean environment. 54 | .LINK 55 | Copy-DoPxBackup 56 | .LINK 57 | Remove-DoPxBackup 58 | .LINK 59 | Rename-DoPxBackup 60 | .LINK 61 | Restore-DoPxBackup 62 | #> 63 | function Get-DoPxBackup { 64 | [CmdletBinding(SupportsPaging=$true)] 65 | [OutputType('digitalocean.backup')] 66 | param( 67 | # The numeric id of a droplet that was backed up. 68 | [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] 69 | [ValidateNotNull()] 70 | [ValidateRange(1,[System.Int32]::MaxValue)] 71 | [Alias('Id')] 72 | [System.Int32[]] 73 | $DropletId, 74 | 75 | # The access token for your DigitalOcean account, in secure string format. 76 | [Parameter()] 77 | [ValidateNotNull()] 78 | [System.Security.SecureString] 79 | $AccessToken 80 | ) 81 | process { 82 | try { 83 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('DropletId')) { 84 | #region Get all backups from all snapshots. 85 | 86 | $passThruParameters = $PSCmdlet.MyInvocation.BoundParameters 87 | Get-DoPxDroplet @passThruParameters | Get-DoPxBackup @passThruParameters 88 | 89 | #endregion 90 | } else { 91 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 92 | CommandName = 'Get-DoPxObject' 93 | CommandType = 'Function' 94 | PreProcessScriptBlock = { 95 | #region Move the id from the DropletId parameter to the Id parameter. 96 | 97 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DropletId 98 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DropletId') > $null 99 | 100 | #endregion 101 | 102 | #region Add additional required parameters to the BoundParameters hashtable. 103 | 104 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 105 | $PSCmdlet.MyInvocation.BoundParameters['RelatedObjectUri'] = 'backups' 106 | 107 | #endregion 108 | } 109 | } 110 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 111 | Invoke-Snippet -Name ProxyFunction.End 112 | } 113 | } catch { 114 | $PSCmdlet.ThrowTerminatingError($_) 115 | } 116 | } 117 | } 118 | 119 | Export-ModuleMember -Function Get-DoPxBackup -------------------------------------------------------------------------------- /functions/Get-DoPxSshKey.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the ssh keys that have been added to your DigitalOcean account. 26 | .DESCRIPTION 27 | The Get-DoPxSshKey command gets the ssh keys that have been added to your DigitalOcean account. 28 | 29 | Without the Id parameter, Get-DoPxSshKey gets all of the ssh keys that have been added to your DigitalOcean account. You can also use Get-DoPxSshKey command to get specific ssh keys by passing the ssh key IDs to the Id parameter or fingerprints to the Fingerprint parameter. 30 | .PARAMETER First 31 | Get only the specified number of ssh keys. 32 | .PARAMETER Skip 33 | Skip the specified number of ssh keys. If this parameter is used in conjunction with the First parameter, the specified number of ssh keys will be skipped before the paging support starts counting the first ssh keys to return. 34 | .PARAMETER IncludeTotalCount 35 | Return the total count of ssh keys that will be returned before returning the ssh keys themselves. 36 | .INPUTS 37 | None 38 | .OUTPUTS 39 | digitalocean.sshkey 40 | .NOTES 41 | This command sends an HTTP GET request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 42 | .EXAMPLE 43 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 44 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 45 | PS C:\> Get-DoPxSshKey 46 | 47 | This command gets all ssh keys that have been added to your DigitalOcean account. 48 | .EXAMPLE 49 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 50 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 51 | PS C:\> Get-DoPxSshKey -Id 542108 52 | 53 | This command gets the ssh key with id 542108 from your DigitalOcean account. 54 | .EXAMPLE 55 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 56 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 57 | PS C:\> Get-DoPxSshKey -Fingerprint 0b:87:45:bd:f0:bf:c9:26:fc:79:1c:ea:d2:a3:e5:36 58 | 59 | This command gets the ssh key that has the fingerprint '0b:87:45:bd:f0:bf:c9:26:fc:79:1c:ea:d2:a3:e5:36' from your DigitalOcean account. 60 | .LINK 61 | Add-DoPxSshKey 62 | .LINK 63 | Rename-DoPxSshKey 64 | .LINK 65 | Remove-DoPxSshKey 66 | #> 67 | function Get-DoPxSshKey { 68 | [CmdletBinding(SupportsPaging=$true,DefaultParameterSetName='Id')] 69 | [OutputType('digitalocean.sshkey')] 70 | param( 71 | # The numeric id of the ssh key. 72 | [Parameter(Position=0, ParameterSetName='Id')] 73 | [ValidateNotNull()] 74 | [ValidateRange(1,[System.Int32]::MaxValue)] 75 | [System.Int32[]] 76 | $Id, 77 | 78 | # The fingerprint of the ssh key. 79 | [Parameter(Position=0, Mandatory=$true, ParameterSetName='Fingerprint')] 80 | [ValidateNotNullOrEmpty()] 81 | [System.String[]] 82 | $Fingerprint, 83 | 84 | # The access token for your DigitalOcean account, in secure string format. 85 | [Parameter()] 86 | [ValidateNotNull()] 87 | [System.Security.SecureString] 88 | $AccessToken 89 | ) 90 | begin { 91 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 92 | CommandName = 'Get-DoPxObject' 93 | CommandType = 'Function' 94 | PreProcessScriptBlock = { 95 | #region Set up the ID properly if a fingerprint is being used in the search. 96 | 97 | if ($PSCmdlet.ParameterSetName -eq 'Fingerprint') { 98 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $Fingerprint 99 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Fingerprint') > $null 100 | } 101 | 102 | #endregion 103 | 104 | #region Add additional required parameters to the BoundParameters hashtable. 105 | 106 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'account/keys' 107 | 108 | #endregion 109 | } 110 | } 111 | } 112 | process { 113 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 114 | } 115 | end { 116 | Invoke-Snippet -Name ProxyFunction.End 117 | } 118 | } 119 | 120 | Export-ModuleMember -Function Get-DoPxSshKey -------------------------------------------------------------------------------- /functions/Get-DoPxSnapshot.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Gets the snapshots that are available in your DigitalOcean account. 26 | .DESCRIPTION 27 | The Get-DoPxSnapshot command gets the snapshots that are available in your DigitalOcean account. 28 | 29 | Without the DropletId parameter, Get-DoPxSnapshot gets all of the snapshots that are available in your DigitalOcean account. You can also use Get-DoPxSnapshot command to get snapshots for a specific droplet by passing the droplet IDs to the DropletId parameter. 30 | .PARAMETER First 31 | Get only the specified number of snapshots. 32 | .PARAMETER Skip 33 | Skip the specified number of snapshots. If this parameter is used in conjunction with the First parameter, the specified number of snapshots will be skipped before the paging support starts counting the first snapshots to return. 34 | .PARAMETER IncludeTotalCount 35 | Return the total count of snapshots that will be returned before returning the snapshots themselves. 36 | .INPUTS 37 | None 38 | .OUTPUTS 39 | digitalocean.snapshot 40 | .NOTES 41 | This command sends an HTTP GET request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 42 | .EXAMPLE 43 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 44 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 45 | PS C:\> Get-DoPxSnapshot 46 | 47 | This command gets all snapshots that have been created in your DigitalOcean environment. 48 | .EXAMPLE 49 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 50 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 51 | PS C:\> Get-DoPxSnapshot -DropletId 4849480 52 | 53 | This command gets all snapshots that have been created from the droplet with id 4849480 in your DigitalOcean environment. 54 | .LINK 55 | Copy-DoPxSnapshot 56 | .LINK 57 | New-DoPxSnapshot 58 | .LINK 59 | Remove-DoPxSnapshot 60 | .LINK 61 | Rename-DoPxSnapshot 62 | .LINK 63 | Restore-DoPxSnapshot 64 | #> 65 | function Get-DoPxSnapshot { 66 | [CmdletBinding(SupportsPaging=$true)] 67 | [OutputType('digitalocean.snapshot')] 68 | param( 69 | # The numeric id of a droplet where a snapshot was taken. 70 | [Parameter(Position=0, ValueFromPipelineByPropertyName=$true)] 71 | [ValidateNotNull()] 72 | [ValidateRange(1,[System.Int32]::MaxValue)] 73 | [Alias('Id')] 74 | [System.Int32[]] 75 | $DropletId, 76 | 77 | # The access token for your DigitalOcean account, in secure string format. 78 | [Parameter()] 79 | [ValidateNotNull()] 80 | [System.Security.SecureString] 81 | $AccessToken 82 | ) 83 | process { 84 | try { 85 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('DropletId')) { 86 | #region Get all snapshots from all droplets. 87 | 88 | $passThruParameters = $PSCmdlet.MyInvocation.BoundParameters 89 | Get-DoPxDroplet @passThruParameters | Get-DoPxSnapshot @passThruParameters 90 | 91 | #endregion 92 | } else { 93 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 94 | CommandName = 'Get-DoPxObject' 95 | CommandType = 'Function' 96 | PreProcessScriptBlock = { 97 | #region Move the id from the DropletId parameter to the Id parameter. 98 | 99 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DropletId 100 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DropletId') > $null 101 | 102 | #endregion 103 | 104 | #region Add additional required parameters to the BoundParameters hashtable. 105 | 106 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 107 | $PSCmdlet.MyInvocation.BoundParameters['RelatedObjectUri'] = 'snapshots' 108 | 109 | #endregion 110 | } 111 | } 112 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 113 | Invoke-Snippet -Name ProxyFunction.End 114 | } 115 | } catch { 116 | $PSCmdlet.ThrowTerminatingError($_) 117 | } 118 | } 119 | } 120 | 121 | Export-ModuleMember -Function Get-DoPxSnapshot -------------------------------------------------------------------------------- /helpers/Get-DoPxObject.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | function Get-DoPxObject { 24 | [CmdletBinding(SupportsPaging=$true)] 25 | [OutputType('digitalocean.object')] 26 | param( 27 | [Parameter(Position=0, Mandatory=$true)] 28 | [ValidateNotNullOrEmpty()] 29 | [System.String] 30 | $RelativeUri, 31 | 32 | [Parameter(Position=1)] 33 | [ValidateNotNullOrEmpty()] 34 | [System.String[]] 35 | $Id, 36 | 37 | [Parameter(Position=2)] 38 | [ValidateNotNullOrEmpty()] 39 | [System.String] 40 | $RelatedObjectUri, 41 | 42 | [Parameter(Position=3)] 43 | [ValidateNotNullOrEmpty()] 44 | [System.String[]] 45 | $RelatedObjectId, 46 | 47 | [Parameter()] 48 | [ValidateNotNullOrEmpty()] 49 | [System.Security.SecureString] 50 | $AccessToken, 51 | 52 | [Parameter()] 53 | [System.Management.Automation.SwitchParameter] 54 | $HeadersOnly 55 | ) 56 | try { 57 | #region If RelatedObjectId is used without the Id parameter, raise an error. 58 | 59 | $PSCmdlet.ValidateParameterDependency('RelatedObjectUri','Id') 60 | 61 | #endregion 62 | 63 | #region If RelatedObjectId is used without the RelatedObjectUri parameter, raise an error. 64 | 65 | $PSCmdlet.ValidateParameterDependency('RelatedObjectId','RelatedObjectUri') 66 | 67 | #endregion 68 | 69 | #region If the paging parameters are used with the HeadersOnly parameter, raise an error. 70 | 71 | $PSCmdlet.ValidateParameterIncompatibility('HeadersOnly',@('First','Skip','IncludeTotalCount')) 72 | 73 | #endregion 74 | 75 | #region Identify the passthru Paging parameters. 76 | 77 | $pagingParameters = $PSCmdlet.GetBoundPagingParameters() 78 | 79 | #endregion 80 | 81 | #region Add the relative uri with the endpoint prefix. 82 | 83 | $uri = "${script:DigitalOceanEndpointUri}/$($RelativeUri -replace '^/+|/+$')" 84 | 85 | #endregion 86 | 87 | #region Prefix the Uri parameters with a slash if not present. 88 | 89 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Id')) { 90 | $internalId = '' -as [System.String[]] 91 | } else { 92 | $internalId = $Id -replace '^([^/])','/$1' -as $Id.GetType() 93 | } 94 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('RelatedObjectUri')) { 95 | $internalRelatedObjectUri = '' -as [System.String] 96 | } else { 97 | $internalRelatedObjectUri = $RelatedObjectUri -replace '^([^/])','/$1' -as $RelatedObjectUri.GetType() 98 | } 99 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('RelatedObjectId')) { 100 | $internalRelatedObjectId = '' -as [System.String[]] 101 | } else { 102 | $internalRelatedObjectId = $RelatedObjectId -replace '^([^/])','/$1' -as $RelatedObjectId.GetType() 103 | } 104 | 105 | #endregion 106 | 107 | #region Determine if we're invoking a GET or a HEAD request. 108 | 109 | if ($PSCmdlet.MyInvocation.BoundParameters.ContainsKey('HeadersOnly') -and $HeadersOnly) { 110 | $method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Head 111 | } else { 112 | $method = [Microsoft.PowerShell.Commands.WebRequestMethod]::Get 113 | } 114 | 115 | #endregion 116 | 117 | #region Initialize the web request headers. 118 | 119 | $accessTokenParameter = $PSCmdlet.GetSplattableParameters('AccessToken') 120 | $headers = Get-DoPxWebRequestHeader @accessTokenParameter 121 | 122 | #endregion 123 | 124 | foreach ($item in $internalId) { 125 | foreach ($relatedItem in $internalRelatedObjectId) { 126 | #region Construct the Uri according to the parameter values used in this iteration. 127 | 128 | $endpointUri = $uri 129 | if ($item) { 130 | $endpointUri += $item 131 | } 132 | if ($internalRelatedObjectUri) { 133 | $endpointUri += "${internalRelatedObjectUri}${relatedItem}" 134 | } 135 | 136 | #endregion 137 | 138 | #region Invoke the web request. 139 | 140 | Invoke-DoPxWebRequest -Uri $endpointUri -Method $method -Headers $headers @pagingParameters 141 | 142 | #endregion 143 | } 144 | } 145 | } catch { 146 | $PSCmdlet.ThrowTerminatingError($_) 147 | } 148 | } 149 | 150 | Export-ModuleMember -Function Get-DoPxObject -------------------------------------------------------------------------------- /functions/Add-DoPxDomain.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Adds a domain to your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Add-DoPxDomain command adds a domains to your DigitalOcean environment. Domain resources are domain names that you have purchased from a domain name registrar that you are managing through the DigitalOcean DNS interface. 28 | 29 | When you add a domain to your DigitalOcean environment, DigitalOcean automatically creates NS records to associate that domain with a droplet that is in your DigitalOcean environment on each of the DigitalOcean DNS servers. 30 | .INPUTS 31 | None 32 | .OUTPUTS 33 | digitalocean.domain 34 | .NOTES 35 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 36 | .EXAMPLE 37 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 38 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 39 | PS C:\> Add-DoPxDomain -Name example.com -IPAddress 192.241.104.96 40 | 41 | This command adds a domain named example.com to your DigitalOcean environment and associates it with the IP address 192.241.104.96. 42 | .LINK 43 | Get-DoPxDomain 44 | .LINK 45 | Get-DoPxDroplet 46 | .LINK 47 | Remove-DoPxDomain 48 | #> 49 | function Add-DoPxDomain { 50 | [CmdletBinding(SupportsShouldProcess=$true,DefaultParameterSetName='Droplet')] 51 | [OutputType('digitalocean.domain')] 52 | param( 53 | # The name of the domain. 54 | [Parameter(Position=0, Mandatory=$true)] 55 | [ValidateNotNullOrEmpty()] 56 | [System.String] 57 | $Name, 58 | 59 | # The IP address of the droplet that you want to associate with the domain. 60 | [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true, ParameterSetName='Droplet')] 61 | [ValidateNotNull()] 62 | [ValidateRange(1,[System.Int32]::MaxValue)] 63 | [Alias('Id')] 64 | [System.Int32] 65 | $DropletId, 66 | 67 | # The IP address of the droplet that you want to associate with the domain. 68 | [Parameter(Position=1, Mandatory=$true, ValueFromPipelineByPropertyName=$true, ParameterSetName='IPAddress')] 69 | [ValidateNotNullOrEmpty()] 70 | [System.String] 71 | $IPAddress, 72 | 73 | # The access token for your DigitalOcean environment, in secure string format. 74 | [Parameter()] 75 | [ValidateNotNull()] 76 | [System.Security.SecureString] 77 | $AccessToken 78 | ) 79 | process { 80 | try { 81 | if ($PSCmdlet.ParameterSetName -eq 'Droplet') { 82 | $accessTokenParameter = $PSCmdlet.GetSplattableParameters('AccessToken') 83 | if ($_.PSTypeNames -contains 'digitalocean.droplet') { 84 | $droplet = $_ 85 | } else { 86 | $droplet = Get-DoPxDroplet -Id $DropletId @accessTokenParameter 87 | } 88 | Add-DoPxDomain -Name $Name -IPAddress $droplet.networks.v4.ip_address @accessTokenParameter 89 | } else { 90 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 91 | CommandName = 'New-DoPxObject' 92 | CommandType = 'Function' 93 | PreProcessScriptBlock = { 94 | #region Identify the endpoint that is used when adding a domain. 95 | 96 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'domains' 97 | 98 | #endregion 99 | 100 | #region Identify the properties that will be assigned to the domain you are adding. 101 | 102 | $PSCmdlet.MyInvocation.BoundParameters['Property'] = @{ 103 | name = $Name 104 | ip_address = $IPAddress 105 | } 106 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Name') > $null 107 | $PSCmdlet.MyInvocation.BoundParameters.Remove('IPAddress') > $null 108 | 109 | #endregion 110 | } 111 | } 112 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 113 | Invoke-Snippet -Name ProxyFunction.End 114 | } 115 | } catch { 116 | $PSCmdlet.ThrowTerminatingError($_) 117 | } 118 | } 119 | } 120 | 121 | Export-ModuleMember -Function Add-DoPxDomain -------------------------------------------------------------------------------- /functions/Wait-DoPxAction.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Waits for one or more DigitalOcean actions to complete. 26 | .DESCRIPTION 27 | The Wait-DoPxAction command waits for one or more DigitalOcean actions to complete. 28 | .INPUTS 29 | digitalocean.action 30 | .OUTPUTS 31 | digitalocean.action 32 | .NOTES 33 | This command sends an HTTP GET request that includes your access token to the DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Wait-DoPxAction -Id 51666486 38 | 39 | This command waits for the action with id 51666486 to finish running. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Get-DoPxAction -Id 51666486 | Wait-DoPxAction 44 | 45 | This command gets the action with id 51666486 from your DigitalOcean environment and waits until that action has finished running. 46 | .LINK 47 | Get-DoPxAction 48 | .LINK 49 | Receive-DoPxAction 50 | #> 51 | function Wait-DoPxAction { 52 | [CmdletBinding(SupportsShouldProcess=$true)] 53 | [OutputType('digitalocean.action')] 54 | param( 55 | # The numeric id of the action. 56 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 57 | [ValidateNotNull()] 58 | [ValidateRange(1,[System.Int32]::MaxValue)] 59 | [System.Int32[]] 60 | $Id, 61 | 62 | # The access token for your DigitalOcean account, in secure string format. 63 | [Parameter()] 64 | [ValidateNotNull()] 65 | [System.Security.SecureString] 66 | $AccessToken 67 | ) 68 | begin { 69 | try { 70 | #region Get a splattable AccessToken parameter. 71 | 72 | $accessTokenParameter = $PSCmdlet.GetSplattableParameters('AccessToken') 73 | 74 | #endregion 75 | 76 | #region Create an array to store the actions we are waiting for. 77 | 78 | $actions = @() 79 | 80 | #endregion 81 | } catch { 82 | $PSCmdlet.ThrowTerminatingError($_) 83 | } 84 | } 85 | process { 86 | try { 87 | #region Get the current state of the action. 88 | 89 | if ($_.PSTypeNames -contains 'digitalocean.action') { 90 | $actions += $_ 91 | } else { 92 | $actions += Get-DoPxAction -Id $Id @accessTokenParameter 93 | } 94 | 95 | #endregion 96 | } catch { 97 | $PSCmdlet.ThrowTerminatingError($_) 98 | } 99 | } 100 | end { 101 | try { 102 | #region Wait until the actions have finished running. 103 | 104 | $completedActionIds = @() 105 | do { 106 | # Sleep for 500 milliseconds between checks 107 | Start-Sleep -Milliseconds 500 108 | for ($index = 0; $index -lt $actions.Count; $index++) { 109 | # Get the current action 110 | $action = $actions[$index] 111 | # If this action already completed and was processed, skip it 112 | if ($completedActionIds -contains $action.id) { 113 | continue 114 | } 115 | # If this action has completed, process it 116 | if ($action.completed_at -ne $null) { 117 | # Add the action id to the list of completed actions that were processed 118 | $completedActionIds += $action.id 119 | # Return the action once it completes successfully 120 | $action 121 | # Now process the next action 122 | continue 123 | } 124 | # Refresh the actions that are not processed and that have not completed yet 125 | $actions[$index] = $action = Get-DoPxAction -Id $action.id @accessTokenParameter 126 | } 127 | } while ($completedActionIds.Count -lt $actions.Count) 128 | 129 | #endregion 130 | } catch { 131 | $PSCmdlet.ThrowTerminatingError($_) 132 | } 133 | } 134 | } 135 | 136 | Export-ModuleMember -Function Wait-DoPxAction -------------------------------------------------------------------------------- /functions/Restart-DoPxDroplet.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Restart a droplet that is currently turned on in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Restart-DoPxDroplet command restarts a droplet that is currently turned on in your DigitalOcean environment. By default this uses the operating system's native restart feature. If the -Force parameter is used, the droplet is power cycled instead. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Restart-DoPxDroplet -Id 4849480 38 | 39 | This command restarts the droplet with id 4849480. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Restart-DoPxDroplet -Id 4849480 -Force 44 | 45 | This command power cycles the droplet with id 4849480. 46 | .EXAMPLE 47 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 48 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 49 | PS C:\> Get-DoPxDroplet | Where-Object {$_.Status -eq 'active'} | Restart-DoPxDroplet 50 | 51 | This command restarts all droplets that are currently turned on. 52 | .LINK 53 | Disable-DoPxDropletOption 54 | .LINK 55 | Enable-DoPxDropletOption 56 | .LINK 57 | Get-DoPxBackup 58 | .LINK 59 | Get-DoPxDroplet 60 | .LINK 61 | Get-DoPxKernel 62 | .LINK 63 | Get-DoPxSnapshot 64 | .LINK 65 | New-DoPxDroplet 66 | .LINK 67 | Remove-DoPxDroplet 68 | .LINK 69 | Rename-DoPxDroplet 70 | .LINK 71 | Reset-DoPxDroplet 72 | .LINK 73 | Resize-DoPxDroplet 74 | .LINK 75 | Start-DoPxDroplet 76 | .LINK 77 | Stop-DoPxDroplet 78 | #> 79 | function Restart-DoPxDroplet { 80 | [CmdletBinding(SupportsShouldProcess=$true)] 81 | [OutputType('digitalocean.action')] 82 | [OutputType('digitalocean.droplet')] 83 | param( 84 | # The numeric id of one or more droplets that you want to restart. 85 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 86 | [ValidateNotNull()] 87 | [ValidateRange(1,[System.Int32]::MaxValue)] 88 | [System.Int32[]] 89 | $Id, 90 | 91 | # Power cycle the droplet instead of gracefully restarting it using the operating system. This parameter should only be used if restarting it gracefully failed. 92 | [Parameter()] 93 | [System.Management.Automation.SwitchParameter] 94 | $Force = $false, 95 | 96 | # The access token for your DigitalOcean account, in secure string format. 97 | [Parameter()] 98 | [ValidateNotNull()] 99 | [System.Security.SecureString] 100 | $AccessToken, 101 | 102 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 103 | [Parameter()] 104 | [System.Management.Automation.SwitchParameter] 105 | $Wait 106 | ) 107 | process { 108 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 109 | CommandName = 'Invoke-DoPxObjectAction' 110 | CommandType = 'Function' 111 | PreProcessScriptBlock = { 112 | #region Remove the -Force parameter if it was used. 113 | 114 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Force') > $null 115 | 116 | #endregion 117 | 118 | #region Add additional required parameters to the BoundParameters hashtable. 119 | 120 | if ($Force) { 121 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'power_cycle' 122 | } else { 123 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'reboot' 124 | } 125 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 126 | 127 | #endregion 128 | } 129 | } 130 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 131 | Invoke-Snippet -Name ProxyFunction.End 132 | } 133 | } 134 | 135 | Export-ModuleMember -Function Restart-DoPxDroplet -------------------------------------------------------------------------------- /functions/Stop-DoPxDroplet.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Shuts down a droplet that is currently turned on in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Stop-DoPxDroplet command shuts down a droplet that is currently turned on in your DigitalOcean environment. By default this uses the operating system's native shut down feature. If the -Force parameter is used, the droplet is immediately turned off instead. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Stop-DoPxDroplet -Id 4849480 38 | 39 | This command shuts down the droplet with id 4849480. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Stop-DoPxDroplet -Id 4849480 -Force 44 | 45 | This command turns off the droplet with id 4849480. 46 | .EXAMPLE 47 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 48 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 49 | PS C:\> Get-DoPxDroplet | Where-Object {$_.Status -eq 'active'} | Stop-DoPxDroplet 50 | 51 | This command shuts down all droplets that are currently turned on. 52 | .LINK 53 | Disable-DoPxDropletOption 54 | .LINK 55 | Enable-DoPxDropletOption 56 | .LINK 57 | Get-DoPxBackup 58 | .LINK 59 | Get-DoPxDroplet 60 | .LINK 61 | Get-DoPxKernel 62 | .LINK 63 | Get-DoPxSnapshot 64 | .LINK 65 | New-DoPxDroplet 66 | .LINK 67 | Remove-DoPxDroplet 68 | .LINK 69 | Rename-DoPxDroplet 70 | .LINK 71 | Reset-DoPxDroplet 72 | .LINK 73 | Resize-DoPxDroplet 74 | .LINK 75 | Restart-DoPxDroplet 76 | .LINK 77 | Stop-DoPxDroplet 78 | #> 79 | function Stop-DoPxDroplet { 80 | [CmdletBinding(SupportsShouldProcess=$true)] 81 | [OutputType('digitalocean.action')] 82 | [OutputType('digitalocean.droplet')] 83 | param( 84 | # The numeric id of one or more droplets that you want to shut down. 85 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 86 | [ValidateNotNull()] 87 | [ValidateRange(1,[System.Int32]::MaxValue)] 88 | [System.Int32[]] 89 | $Id, 90 | 91 | # Turn off the droplet immediately instead of gracefully shutting it down using the operating system. This parameter should only be used if shutting it down gracefully failed. 92 | [Parameter()] 93 | [System.Management.Automation.SwitchParameter] 94 | $Force = $false, 95 | 96 | # The access token for your DigitalOcean account, in secure string format. 97 | [Parameter()] 98 | [ValidateNotNull()] 99 | [System.Security.SecureString] 100 | $AccessToken, 101 | 102 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 103 | [Parameter()] 104 | [System.Management.Automation.SwitchParameter] 105 | $Wait 106 | ) 107 | process { 108 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 109 | CommandName = 'Invoke-DoPxObjectAction' 110 | CommandType = 'Function' 111 | PreProcessScriptBlock = { 112 | #region Remove the -Force parameter if it was used. 113 | 114 | $PSCmdlet.MyInvocation.BoundParameters.Remove('Force') > $null 115 | 116 | #endregion 117 | 118 | #region Add additional required parameters to the BoundParameters hashtable. 119 | 120 | if ($Force) { 121 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'power_off' 122 | } else { 123 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'shutdown' 124 | } 125 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 126 | 127 | #endregion 128 | } 129 | } 130 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 131 | Invoke-Snippet -Name ProxyFunction.End 132 | } 133 | } 134 | 135 | Export-ModuleMember -Function Stop-DoPxDroplet -------------------------------------------------------------------------------- /functions/Enable-DoPxDropletOption.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | <# 24 | .SYNOPSIS 25 | Enables IPv6 or private networking on a droplet in your DigitalOcean environment. 26 | .DESCRIPTION 27 | The Enable-DoPxDropletOption command enables IPv6 or private networking on a droplet in your DigitalOcean environment. 28 | .INPUTS 29 | digitalocean.droplet 30 | .OUTPUTS 31 | digutalocean.action,digitalocean.droplet 32 | .NOTES 33 | This command sends an HTTP POST request that includes your access token to a DigitalOcean REST API v2 endpoint. To learn more about the DigitalOcean REST API, consult the DigitalOcean API documentation online at https://developers.digitalocean.com. 34 | .EXAMPLE 35 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 36 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 37 | PS C:\> Enable-DoPxDropletOption -DropletId 4849480 -IPv6 38 | 39 | This command enables IPv6 on the droplet with id 4849480. 40 | .EXAMPLE 41 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 42 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 43 | PS C:\> Enable-DoPxDropletOption -DropletId 4849480 -PrivateNetworking 44 | 45 | This command enables private networking on the droplet with id 4849480. 46 | .EXAMPLE 47 | PS C:\> $accessToken = ConvertTo-SecureString -String a91a22c7d3c572306e9d6ebfce5f1f697bd7fe8d910d9497ca0f75de2bb37a32 -AsPlainText -Force 48 | PS C:\> Set-DoPxDefaultAccessToken -AccessToken $accessToken 49 | PS C:\> Get-DoPxDroplet | Enable-DoPxDropletOption -IPv6 50 | 51 | This command enables automatic backup on all droplets in your DigitalOcean environment. 52 | .LINK 53 | Disable-DoPxDropletOption 54 | .LINK 55 | Get-DoPxDroplet 56 | #> 57 | function Enable-DoPxDropletOption { 58 | [CmdletBinding(SupportsShouldProcess=$true, DefaultParameterSetName='IPv6')] 59 | [OutputType('digitalocean.action')] 60 | [OutputType('digitalocean.droplet')] 61 | param( 62 | # The numeric id of one or more droplets with options that you want to enable. 63 | [Parameter(Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] 64 | [ValidateNotNull()] 65 | [ValidateRange(1,[System.Int32]::MaxValue)] 66 | [Alias('Id')] 67 | [System.Int32[]] 68 | $DropletId, 69 | 70 | # Enables IPv6 on the droplet. 71 | [Parameter(Mandatory=$true, ParameterSetName='IPv6')] 72 | [ValidateScript({ 73 | if (-not $_.IsPresent) { 74 | throw 'Passing false into the IPv6 parameter is not supported.' 75 | } 76 | $true 77 | })] 78 | [System.Management.Automation.SwitchParameter] 79 | $IPv6, 80 | 81 | # Enables private networking on the droplet. 82 | [Parameter(Mandatory=$true, ParameterSetName='PrivateNetworking')] 83 | [ValidateScript({ 84 | if (-not $_.IsPresent) { 85 | throw 'Passing false into the PrivateNetworking parameter is not supported.' 86 | } 87 | $true 88 | })] 89 | [System.Management.Automation.SwitchParameter] 90 | $PrivateNetworking, 91 | 92 | # The access token for your DigitalOcean account, in secure string format. 93 | [Parameter()] 94 | [ValidateNotNull()] 95 | [System.Security.SecureString] 96 | $AccessToken, 97 | 98 | # Waits for the action to complete, and then returns the updated object to the pipeline. By default, this command returns the action to the pipeline. 99 | [Parameter()] 100 | [System.Management.Automation.SwitchParameter] 101 | $Wait 102 | ) 103 | process { 104 | Invoke-Snippet -Name ProxyFunction.Begin -Parameters @{ 105 | CommandName = 'Invoke-DoPxObjectAction' 106 | CommandType = 'Function' 107 | PreProcessScriptBlock = { 108 | #region Replace the DropletId parameter with the Id parameter. 109 | 110 | $PSCmdlet.MyInvocation.BoundParameters['Id'] = $DropletId 111 | $PSCmdlet.MyInvocation.BoundParameters.Remove('DropletId') > $null 112 | 113 | #endregion 114 | 115 | #region Add additional required parameters to the BoundParameters hashtable. 116 | 117 | if ($PSCmdlet.ParameterSetName -eq 'IPv6') { 118 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'enable_ipv6' 119 | } else { 120 | $PSCmdlet.MyInvocation.BoundParameters['Action'] = 'enable_private_networking' 121 | } 122 | $PSCmdlet.MyInvocation.BoundParameters['RelativeUri'] = 'droplets' 123 | 124 | #endregion 125 | } 126 | } 127 | Invoke-Snippet -Name ProxyFunction.Process.NoPipeline 128 | Invoke-Snippet -Name ProxyFunction.End 129 | } 130 | } 131 | 132 | Export-ModuleMember -Function Enable-DoPxDropletOption -------------------------------------------------------------------------------- /helpers/Invoke-DoPxObjectAction.ps1: -------------------------------------------------------------------------------- 1 | <############################################################################# 2 | The DoPx module provides a rich set of commands that extend the automation 3 | capabilities of the DigitalOcean (DO) cloud service. These commands make it 4 | easier to manage your DigitalOcean environment from Windows PowerShell. When 5 | used with the LinuxPx module, you can manage your entire DigitalOcean 6 | environment from one shell. 7 | 8 | Copyright 2014 Kirk Munro 9 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); 11 | you may not use this file except in compliance with the License. 12 | You may obtain a copy of the License at 13 | 14 | http://www.apache.org/licenses/LICENSE-2.0 15 | 16 | Unless required by applicable law or agreed to in writing, software 17 | distributed under the License is distributed on an "AS IS" BASIS, 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 19 | See the License for the specific language governing permissions and 20 | limitations under the License. 21 | #############################################################################> 22 | 23 | function Invoke-DoPxObjectAction { 24 | [CmdletBinding(SupportsShouldProcess=$true)] 25 | [OutputType('digitalocean.object')] 26 | param( 27 | [Parameter(Position=0, Mandatory=$true)] 28 | [ValidateNotNullOrEmpty()] 29 | [System.String] 30 | $RelativeUri, 31 | 32 | [Parameter(Position=1, Mandatory=$true)] 33 | [ValidateNotNullOrEmpty()] 34 | [System.String[]] 35 | $Id, 36 | 37 | [Parameter(Position=2)] 38 | [ValidateNotNullOrEmpty()] 39 | [System.String] 40 | $RelatedObjectUri, 41 | 42 | [Parameter(Position=3)] 43 | [ValidateNotNullOrEmpty()] 44 | [System.String[]] 45 | $RelatedObjectId, 46 | 47 | [Parameter(Mandatory=$true)] 48 | [ValidateNotNullOrEmpty()] 49 | [System.String] 50 | $Action, 51 | 52 | [Parameter()] 53 | [ValidateNotNullOrEmpty()] 54 | [Alias('ParameterValues')] 55 | [System.Collections.Hashtable] 56 | $Parameter = @{}, 57 | 58 | [Parameter()] 59 | [ValidateNotNull()] 60 | [System.Security.SecureString] 61 | $AccessToken, 62 | 63 | [Parameter()] 64 | [System.Management.Automation.SwitchParameter] 65 | $Wait 66 | ) 67 | try { 68 | #region If RelatedObjectId is used without the Id parameter, raise an error. 69 | 70 | $PSCmdlet.ValidateParameterDependency('RelatedObjectUri','Id') 71 | 72 | #endregion 73 | 74 | #region If RelatedObjectId is used without the RelatedObjectUri parameter, raise an error. 75 | 76 | $PSCmdlet.ValidateParameterDependency('RelatedObjectId','RelatedObjectUri') 77 | 78 | #endregion 79 | 80 | #region Identify the passthru ShouldProcess parameters. 81 | 82 | $shouldProcessParameters = $PSCmdlet.GetBoundShouldProcessParameters() 83 | 84 | #endregion 85 | 86 | #region Add the relative uri with the endpoint prefix. 87 | 88 | $uri = "${script:DigitalOceanEndpointUri}/$($RelativeUri -replace '^/+|/+$')" 89 | 90 | #endregion 91 | 92 | #region Prefix the Uri parameters with a slash if not present. 93 | 94 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Id')) { 95 | $internalId = '' -as [System.String[]] 96 | } else { 97 | $internalId = $Id -replace '^([^/])','/$1' -as $Id.GetType() 98 | } 99 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('RelatedObjectUri')) { 100 | $internalRelatedObjectUri = '' -as [System.String] 101 | } else { 102 | $internalRelatedObjectUri = $RelatedObjectUri -replace '^([^/])','/$1' -as $RelatedObjectUri.GetType() 103 | } 104 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('RelatedObjectId')) { 105 | $internalRelatedObjectId = '' -as [System.String[]] 106 | } else { 107 | $internalRelatedObjectId = $RelatedObjectId -replace '^([^/])','/$1' -as $RelatedObjectId.GetType() 108 | } 109 | 110 | #endregion 111 | 112 | #region Add a type parameter with the name of the action being invoked. 113 | 114 | $Parameter['type'] = $Action 115 | 116 | #endregion 117 | 118 | #region Get a splattable AccessToken parameter. 119 | 120 | $accessTokenParameter = $PSCmdlet.GetSplattableParameters('AccessToken') 121 | 122 | #endregion 123 | 124 | #region Initialize the web request headers. 125 | 126 | $headers = Get-DoPxWebRequestHeader @accessTokenParameter 127 | 128 | #endregion 129 | 130 | #region Define an array that will hold the actions created from our requests. 131 | 132 | $actions = @() 133 | 134 | #endregion 135 | 136 | foreach ($item in $internalId) { 137 | foreach ($relatedItem in $internalRelatedObjectId) { 138 | #region Construct the Uri according to the parameter values used in this iteration. 139 | 140 | $endpointUri = $uri 141 | if ($item) { 142 | $endpointUri += $item 143 | } 144 | if ($internalRelatedObjectUri) { 145 | $endpointUri += "${internalRelatedObjectUri}${relatedItem}" 146 | } 147 | $endpointUri += '/actions' 148 | 149 | #endregion 150 | 151 | #region Invoke the web request. 152 | 153 | $actions += Invoke-DoPxWebRequest -Uri $endpointUri -Method Post -Headers $headers -Body $Parameter -PassThru @shouldProcessParameters 154 | 155 | #endregion 156 | } 157 | } 158 | 159 | #region If we are not waiting, return the actions to the caller; otherwise, wait. 160 | 161 | if (-not $PSCmdlet.MyInvocation.BoundParameters.ContainsKey('Wait') -or -not $Wait) { 162 | $actions 163 | } else { 164 | $actions | Wait-DoPxAction @accessTokenParameter | Receive-DoPxAction @accessTokenParameter 165 | } 166 | 167 | #endregion 168 | } catch { 169 | $PSCmdlet.ThrowTerminatingError($_) 170 | } 171 | } 172 | 173 | Export-ModuleMember -Function Invoke-DoPxObjectAction --------------------------------------------------------------------------------