Public/BCDR_Asset.ps1
function Get-DattoAsset { <# .SYNOPSIS Get Datto BCDR assets (agents and shares) for a given device .DESCRIPTION The Get-DattoAsset cmdlet gets Datto BCDR assets (agents and shares) for a given device .PARAMETER serialNumber Defines the BCDR serial number to get The parameter is mandatory .PARAMETER page Defines the page number to return The default value is 1 .PARAMETER perPage Defines the amount of items to return with each page The default value is 100 .PARAMETER allPages Returns all items from an endpoint When using this parameter there is no need to use either the page or perPage parameters .EXAMPLE Get-DattoAsset -serialNumber "12345678" Gets the Datto BCDR with the defined serialNumber and returns any agents or shares. .EXAMPLE Get-DattoAsset -serialNumber "12345678" -page 2 -pageSize 10 Gets the Datto BCDR with the defined serialNumber and returns the first 10 agents or shares from the 2nd page of results. .NOTES N\A .LINK https://celerium.github.io/Datto-PowerShellWrapper/site/BCDR/Get-DattoAsset.html #> [CmdletBinding(DefaultParameterSetName = 'index')] Param ( [Parameter(Mandatory = $true, ValueFromPipeline = $true, ParameterSetName = 'index')] [ValidateNotNullOrEmpty()] [string]$serialNumber, [Parameter(Mandatory = $false, ParameterSetName = 'index')] [ValidateRange(1, [Int64]::MaxValue)] [Int64]$page = 1, [Parameter(Mandatory = $false, ParameterSetName = 'index')] [ValidateRange(1, [Int64]::MaxValue)] [Int64]$perPage = 100, [Parameter( Mandatory = $false, ParameterSetName = 'index')] [Switch]$allPages ) begin{ $resource_uri = "/bcdr/device/$serialNumber/asset" } process{ Write-Verbose "Running the [ $($PSCmdlet.ParameterSetName) ] parameterSet" #Add default PSBoundParameters if( -not $PSBoundParameters.ContainsKey('page') ) { $PSBoundParameters._page = 1 } else { $PSBoundParameters._page = $page } if( -not $PSBoundParameters.ContainsKey('perPage') ) { $PSBoundParameters._perPage = 100 } else { $PSBoundParameters._perPage = $perPage } Set-Variable -Name 'Datto_assetParameters' -Value $PSBoundParameters -Scope Global -Force switch ($allPages) { $true { Invoke-ApiRequest -method GET -resource_Uri $resource_Uri -uri_Filter $PSBoundParameters -allPages } $false { Invoke-ApiRequest -method GET -resource_Uri $resource_Uri -uri_Filter $PSBoundParameters } } } end{} } |