modules/assets.psm1
# /api/v2/assets function Get-PPDMassets { [CmdletBinding()] param( $PPDM_API_BaseUri = $Global:PPDM_API_BaseUri, $apiver = "/api/v2", [Parameter(Mandatory = $false, ParameterSetName = 'byID', ValueFromPipelineByPropertyName = $true)] $id ) begin { $Response = @() $METHOD = "GET" $Myself = ($MyInvocation.MyCommand.Name.Substring(8) -replace "_", "/").ToLower() # $response = Invoke-WebRequest -Method $Method -Uri $Global:PPDM_API_BaseUri/api/v0/$Myself -Headers $Global:PPDM_API_Headers } Process { switch ($PsCmdlet.ParameterSetName) { 'byID' { $URI = "/$myself/$id" } default { $URI = "/$myself" } } try { $Response += Invoke-PPDMapirequest -uri $URI -Method $METHOD -Body "$body" -Verbose:($PSBoundParameters['Verbose'] -eq $true) } catch { Get-PPDMWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'byID' { write-output $response | convertfrom-json } default { write-output ($response | convertfrom-json).content } } } } # /api/v2/assets/{id}/copy-map # /api/v2/assets function Get-PPDMcopy_map { [CmdletBinding()] param( $PPDM_API_BaseUri = $Global:PPDM_API_BaseUri, $apiver = "/api/v2", [Parameter(Mandatory = $true, ParameterSetName = 'byID', ValueFromPipelineByPropertyName = $true)] $id ) begin { $Response = @() $METHOD = "GET" $Myself = ($MyInvocation.MyCommand.Name.Substring(8) -replace "_", "-").ToLower() # $response = Invoke-WebRequest -Method $Method -Uri $Global:PPDM_API_BaseUri/api/v0/$Myself -Headers $Global:PPDM_API_Headers } Process { switch ($PsCmdlet.ParameterSetName) { 'byID' { $URI = "/assets/$id/$myself" } default { $URI = "/assets/$id/$myself" } } try { $Response += Invoke-PPDMapirequest -uri $URI -Method $METHOD -Body "$body" -Verbose:($PSBoundParameters['Verbose'] -eq $true) } catch { Get-PPDMWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'byID' { write-output $response | convertfrom-json } default { write-output ($response | convertfrom-json).content } } } } # /api/v2/assets function Get-PPDMprotection_rules { [CmdletBinding()] param( $PPDM_API_BaseUri = $Global:PPDM_API_BaseUri, $apiver = "/api/v2", [Parameter(Mandatory = $false, ParameterSetName = 'byID', ValueFromPipelineByPropertyName = $true)] $id ) begin { $Response = @() $METHOD = "GET" $Myself = ($MyInvocation.MyCommand.Name.Substring(8) -replace "_", "-").ToLower() # $response = Invoke-WebRequest -Method $Method -Uri $Global:PPDM_API_BaseUri/api/v0/$Myself -Headers $Global:PPDM_API_Headers } Process { switch ($PsCmdlet.ParameterSetName) { 'byID' { $URI = "/$myself/$id" } default { $URI = "/$myself" } } try { $Response += Invoke-PPDMapirequest -uri $URI -Method $METHOD -Body "$body" -Verbose:($PSBoundParameters['Verbose'] -eq $true) } catch { Get-PPDMWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'byID' { write-output $response | convertfrom-json } default { write-output ($response | convertfrom-json).content } } } } # PUT /api/v2/protection-rules/{id} function Set-PPDMprotection_rules { [CmdletBinding()] param( $PPDM_API_BaseUri = $Global:PPDM_API_BaseUri, $apiver = "/api/v2", [Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)] [array]$Protection_rule ) begin { $Response = @() $METHOD = "PUT" $Myself = ($MyInvocation.MyCommand.Name.Substring(8) -replace "_", "-").ToLower() # $response = Invoke-WebRequest -Method $Method -Uri $Global:PPDM_API_BaseUri/api/v0/$Myself -Headers $Global:PPDM_API_Headers } Process { $body = $Protection_rule | convertto-json -Depth 10 switch ($PsCmdlet.ParameterSetName) { default { $URI = "/$myself/$($Protection_rule.id)" } } write-verbose ($body | Out-String) $Parameters = @{ body = $body Uri = $Uri Method = $Method RequestMethod = 'Rest' PPDM_API_BaseUri = $PPDM_API_BaseUri apiver = $apiver ContentType = "application/json" Verbose = $PSBoundParameters['Verbose'] -eq $true } try { $Response += Invoke-PPDMapirequest @Parameters } catch { Get-PPDMWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { write-output $response } } } } # # DELETE /api/v2/protection-rules/{id} function Remove-PPDMprotection_rules { [CmdletBinding()] param( $PPDM_API_BaseUri = $Global:PPDM_API_BaseUri, $apiver = "/api/v2", [Parameter(Mandatory = $true, ValueFromPipeline = $true)] $id ) begin { $Response = @() $METHOD = "DELETE" $Myself = ($MyInvocation.MyCommand.Name.Substring(11) -replace "_", "-").ToLower() # $response = Invoke-WebRequest -Method $Method -Uri $Global:PPDM_API_BaseUri/api/v0/$Myself -Headers $Global:PPDM_API_Headers } Process { switch ($PsCmdlet.ParameterSetName) { default { $URI = "/$myself/$id" } } try { $Response += Invoke-PPDMapirequest -uri $URI -Method $METHOD -Body "$body" -Verbose:($PSBoundParameters['Verbose'] -eq $true) } catch { Get-PPDMWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { default { write-output $response } } } } # GET /api/v2/common-settings/VM_BACKUP_SETTING function Get-PPDMvm_backup_setting { [CmdletBinding()] param( $PPDM_API_BaseUri = $Global:PPDM_API_BaseUri, $apiver = "/api/v2" ) begin { $Response = @() $METHOD = "GET" $Myself = "common-settings/VM_BACKUP_SETTING" # $response = Invoke-WebRequest -Method $Method -Uri $Global:PPDM_API_BaseUri/api/v0/$Myself -Headers $Global:PPDM_API_Headers } Process { switch ($PsCmdlet.ParameterSetName) { default { $URI = "/$myself" } } $Parameters = @{ body = $body Uri = $Uri Method = $Method RequestMethod = 'Rest' PPDM_API_BaseUri = $PPDM_API_BaseUri apiver = $apiver ContentType = "application/json" Verbose = $PSBoundParameters['Verbose'] -eq $true } try { $Response += Invoke-PPDMapirequest @Parameters } catch { Get-PPDMWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'byID' { write-output $response | convertfrom-json } default { write-output $response } } } } function Set-PPDMvm_backup_setting { [CmdletBinding()] param( [Parameter(Mandatory = $true, ValueFromPipeline = $true)] [array]$vm_backup_setting, $PPDM_API_BaseUri = $Global:PPDM_API_BaseUri, $apiver = "/api/v2" ) begin { $Response = @() $METHOD = "PUT" $Myself = "common-settings/VM_BACKUP_SETTING" # $response = Invoke-WebRequest -Method $Method -Uri $Global:PPDM_API_BaseUri/api/v0/$Myself -Headers $Global:PPDM_API_Headers } Process { switch ($PsCmdlet.ParameterSetName) { default { $URI = "/$myself" } } $body=$vm_backup_setting | ConvertTo-Json -Depth 10 $Parameters = @{ body = $body Uri = $Uri Method = $Method RequestMethod = 'Rest' PPDM_API_BaseUri = $PPDM_API_BaseUri apiver = $apiver ContentType = "application/json" Verbose = $PSBoundParameters['Verbose'] -eq $true } try { $Response += Invoke-PPDMapirequest @Parameters } catch { Get-PPDMWebException -ExceptionMessage $_ break } write-verbose ($response | Out-String) } end { switch ($PsCmdlet.ParameterSetName) { 'byID' { write-output $response | convertfrom-json } default { write-output $response } } } } |