From 20dbb3784c0bbb0d1a41c30fc9164a0fee3d181e Mon Sep 17 00:00:00 2001 From: TehMuffinMoo Date: Wed, 17 Jul 2024 13:13:58 +0100 Subject: [PATCH] Begin work on ShouldProcess --- .../BloxOne/BloxOneCloud/Get-B1APIKey.ps1 | 23 +++++---- .../BloxOne/BloxOneCloud/Get-B1AuditLog.ps1 | 26 ++++++---- .../BloxOneCloud/Get-B1BulkOperation.ps1 | 22 ++++++--- .../BloxOneCloud/Get-B1CSPCurrentUser.ps1 | 29 +++++++++--- .../BloxOneCloud/Get-B1Compartment.ps1 | 20 ++++++-- .../BloxOne/BloxOneCloud/Get-B1DFPLog.ps1 | 24 +++++++--- .../BloxOne/BloxOneCloud/Get-B1DHCPLog.ps1 | 26 ++++++---- .../BloxOne/BloxOneCloud/Get-B1DNSEvent.ps1 | 22 ++++++--- .../BloxOne/BloxOneCloud/Get-B1DNSLog.ps1 | 44 ++++++++++------- .../BloxOneCloud/Get-B1DiagnosticTask.ps1 | 47 ++++++++++++------- .../BloxOne/BloxOneCloud/Get-B1Export.ps1 | 21 +++++++-- .../BloxOne/BloxOneCloud/Get-B1Licenses.ps1 | 23 ++++++--- .../BloxOne/BloxOneCloud/Get-B1Location.ps1 | 21 ++++++--- .../BloxOneCloud/Get-B1SecurityLog.ps1 | 38 +++++++++------ .../BloxOne/BloxOneCloud/Get-B1ServiceLog.ps1 | 36 +++++++++----- .../BloxOne/BloxOneCloud/Get-B1Tag.ps1 | 21 +++++++-- .../BloxOne/BloxOneCloud/Get-B1User.ps1 | 29 ++++++++---- .../BloxOne/BloxOneCloud/Get-B1UserAPIKey.ps1 | 31 +++++++----- .../BloxOne/BloxOneCloud/New-B1APIKey.ps1 | 47 ++++++++++++------- .../BloxOne/BloxOneCloud/New-B1Location.ps1 | 21 ++++++--- .../BloxOne/BloxOneCloud/Remove-B1APIKey.ps1 | 36 +++++++++----- .../BloxOneCloud/Remove-B1Location.ps1 | 23 ++++++--- .../BloxOne/BloxOneCloud/Search-B1.ps1 | 24 +++++++--- .../BloxOne/BloxOneCloud/Set-B1APIKey.ps1 | 23 ++++++--- .../BloxOne/BloxOneCloud/Set-B1Location.ps1 | 21 ++++++--- .../BloxOne/BloxOneCloud/Start-B1Export.ps1 | 25 ++++++---- .../Start-B1DiagnosticTask.ps1 | 8 ++-- Modules/ibPS/Functions/Misc/Misc.ps1 | 20 ++++++++ RELEASE.md | 27 ++++++++++- 29 files changed, 546 insertions(+), 232 deletions(-) diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1APIKey.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1APIKey.ps1 index 778801fa..b2ea965c 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1APIKey.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1APIKey.ps1 @@ -44,6 +44,9 @@ .PARAMETER id The id of the API Key to filter by + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1APIKey -User "user@domain.corp" -Name "somename" -Type "interactive" -State Enabled @@ -53,6 +56,10 @@ .FUNCTIONALITY Authentication #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [String]$User, [string]$CreatedBy, @@ -67,9 +74,10 @@ [String[]]$Fields, [String]$OrderBy, $CustomFilters, - [String]$id + [String]$id, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters [System.Collections.ArrayList]$Filters = @() [System.Collections.ArrayList]$QueryFilters = @() $MatchType = Match-Type $Strict @@ -116,11 +124,10 @@ } Write-DebugMsg -Filters $QueryFilters - - $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/api_keys$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue - - if ($Results) { - return $Results + if($PSCmdlet.ShouldProcess('List API Keys','List API Keys',$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/api_keys$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if ($Results) { + return $Results + } } - } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1AuditLog.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1AuditLog.ps1 index da35be3c..cd838923 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1AuditLog.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1AuditLog.ps1 @@ -49,6 +49,9 @@ Accepts either an Object, ArrayList or String containing one or more custom filters. See here for usage: https://ibps.readthedocs.io/en/latest/#-customfilters + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1AuditLog -Limit "25" -Offset "0" -Username "my.email@domain.com" -Method "POST" -Action "Create" -ClientIP "1.2.3.4" -ResponseCode "200" @@ -58,6 +61,10 @@ .FUNCTIONALITY Logs #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [string]$Username, [string]$ResourceType, @@ -73,9 +80,10 @@ [String]$OrderBy, [String[]]$Fields, $CustomFilters, - [switch]$Strict + [switch]$Strict, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $Start = $Start.ToUniversalTime() $End = $End.ToUniversalTime() @@ -135,11 +143,13 @@ Write-DebugMsg -Filters $QueryFilters if ($QueryString) { - $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/api/auditlog/v1/logs$QueryString" -Method GET | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue - } - if ($Results) { - return $Results - } else { - return $null + if($PSCmdlet.ShouldProcess('Retrive Audit Log','Retrive Audit Log',$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/api/auditlog/v1/logs$QueryString" -Method GET | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + if ($Results) { + return $Results + } else { + return $null + } + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1BulkOperation.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1BulkOperation.ps1 index e9dca0e5..bff2dde5 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1BulkOperation.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1BulkOperation.ps1 @@ -18,6 +18,9 @@ .PARAMETER Fields Specify a list of fields to return. The default is to return all fields. + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1BulkOperation -Name "Backup of all CSP data" @@ -27,12 +30,17 @@ .FUNCTIONALITY Tasks #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [string]$id, [string]$Name, - [switch]$Strict = $false + [Switch]$Strict, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $MatchType = Match-Type $Strict [System.Collections.ArrayList]$Filters = @() [System.Collections.ArrayList]$QueryFilters = @() @@ -52,9 +60,11 @@ Write-DebugMsg -Filters $QueryFilters - if ($QueryString) { - Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/operation$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue - } else { - Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/operation" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if($PSCmdlet.ShouldProcess('Query Bulk Operations','Query Bulk Operations',$MyInvocation.MyCommand)){ + if ($QueryString) { + Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/operation$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } else { + Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/operation" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1CSPCurrentUser.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1CSPCurrentUser.ps1 index a022782d..3ffb0f13 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1CSPCurrentUser.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1CSPCurrentUser.ps1 @@ -15,6 +15,9 @@ .PARAMETER Account Using the -Account switch will return the account data associated with the current user + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1CSPCurrentUser @@ -24,22 +27,36 @@ .FUNCTIONALITY Authentication #> - [CmdletBinding(DefaultParameterSetName = 'None')] + [CmdletBinding( + DefaultParameterSetName = 'None', + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [Parameter(ParameterSetName="Groups")] [Switch]$Groups, [Parameter(ParameterSetName="Account")] [Switch]$Account, [Parameter(ParameterSetName="Compartments")] - [Switch]$Compartments + [Switch]$Compartments, + [Switch]$Force ) + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters if ($Groups) { - Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/groups" | Select-Object -ExpandProperty results + if($PSCmdlet.ShouldProcess("List The Current CSP User`'s Groups","List Current CSP User`'s Groups",$MyInvocation.MyCommand)){ + Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/groups" | Select-Object -ExpandProperty results + } } elseif ($Account) { - Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/accounts" | Select-Object -ExpandProperty results + if($PSCmdlet.ShouldProcess("List The Current CSP User`'s Accounts","List Current CSP User`'s Accounts",$MyInvocation.MyCommand)){ + Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/accounts" | Select-Object -ExpandProperty results + } } elseif ($Compartments) { - Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/compartments" | Select-Object -ExpandProperty results + if($PSCmdlet.ShouldProcess("List The Current CSP User`'s Compartments","List Current CSP User`'s Compartments",$MyInvocation.MyCommand)){ + Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/compartments" | Select-Object -ExpandProperty results + } } else { - Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user" | Select-Object -ExpandProperty result + if($PSCmdlet.ShouldProcess("List The Current CSP User`'s Details","List Current CSP User`'s Details",$MyInvocation.MyCommand)){ + Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user" | Select-Object -ExpandProperty result + } } } diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Compartment.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Compartment.ps1 index 579c37d5..24184a9b 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Compartment.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Compartment.ps1 @@ -31,6 +31,9 @@ .PARAMETER id The id of the API Key to filter by + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1APIKey -User "user@domain.corp" -Name "somename" -Type "interactive" -State Enabled @@ -40,6 +43,10 @@ .FUNCTIONALITY Authentication #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [String]$Name, [Int]$Limit, @@ -48,9 +55,10 @@ [String[]]$Fields, [String]$OrderBy, $CustomFilters, - [String]$id + [String]$id, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters [System.Collections.ArrayList]$Filters = @() [System.Collections.ArrayList]$QueryFilters = @() $MatchType = Match-Type $Strict @@ -84,8 +92,10 @@ $QueryString = ConvertTo-QueryString $QueryFilters } Write-DebugMsg -Filters $QueryFilters - $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/compartments$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue - if ($Results) { - return $Results + if($PSCmdlet.ShouldProcess('List Compartments','List Compartments',$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/compartments$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if ($Results) { + return $Results + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DFPLog.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DFPLog.ps1 index d86d9b3a..bbe9f5e2 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DFPLog.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DFPLog.ps1 @@ -39,6 +39,9 @@ .PARAMETER Offset Use this parameter to offset the results by the value entered for the purpose of pagination + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1DFPLog -IP "10.10.132.10" -Query "google.com" -Type "A" -Response "216.58.201.110" -Start (Get-Date).AddHours(-6) -End (Get-Date) -Limit 1000 -Offset 0 @@ -51,6 +54,10 @@ .FUNCTIONALITY Logs #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [string]$Query, [string]$IP, @@ -63,9 +70,10 @@ [ValidateSet('asc','desc')] [String]$Order = 'asc', [int]$Limit = 100, - [int]$Offset = 0 + [int]$Offset = 0, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $Cube = 'PortunusDnsLogs' $Dimensions = @( @@ -158,10 +166,12 @@ } } - $Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order - if ($Result) { - return $Result - } else { - Write-Host "Error: No DNS logs returned." -ForegroundColor Red + if($PSCmdlet.ShouldProcess("Query the DNS Activity Logs","Query the DNS Activity Logs",$MyInvocation.MyCommand)){ + $Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order + if ($Result) { + return $Result + } else { + Write-Host "Error: No DNS logs returned." -ForegroundColor Red + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DHCPLog.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DHCPLog.ps1 index 5dc658a9..790fac3b 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DHCPLog.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DHCPLog.ps1 @@ -42,6 +42,9 @@ .PARAMETER Offset Use this parameter to offset the results by the value entered for the purpose of pagination + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1DHCPLog -Hostname "dhcpclient.mydomain.corp" -State "Assignments" -IP "10.10.10.100" -Protocol "IPv4 Address" -DHCPServer "bloxoneddihost1.mydomain.corp" -Start (Get-Date).AddHours(-24) -End (Get-Date) -Limit 100 -Offset 0 @@ -54,6 +57,10 @@ .FUNCTIONALITY DHCP #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [string]$Hostname, [string]$State, @@ -67,12 +74,13 @@ [ValidateSet('asc','desc')] [String]$Order = 'asc', [int]$Limit = 100, - [int]$Offset = 0 + [int]$Offset = 0, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $Cube = 'NstarLeaseActivity' - ## Replace with CubeJS Query + ## Replace with CubeJS Query? $DHCPHostQuery = Get-B1DHCPHost -Limit 2500 -Fields id,name $DHCPHosts += $DHCPHostQuery if ($DHCPHostQuery.count -eq 2500) { @@ -177,10 +185,12 @@ } } - $Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order - if ($Result) { - return $Result | Select-Object @{name="dhcp_server";Expression={Match-DHCPHost -id $_.'host_id'}},* - } else { - Write-Host "Error: No DHCP logs returned." -ForegroundColor Red + if($PSCmdlet.ShouldProcess("Query the DHCP Logs","Query the DHCP Logs",$MyInvocation.MyCommand)){ + $Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order + if ($Result) { + return $Result | Select-Object @{name="dhcp_server";Expression={Match-DHCPHost -id $_.'host_id'}},* + } else { + Write-Host "Error: No DHCP logs returned." -ForegroundColor Red + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DNSEvent.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DNSEvent.ps1 index 9d172c8f..c31322ba 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DNSEvent.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DNSEvent.ps1 @@ -66,6 +66,9 @@ .PARAMETER Fields Specify a list of fields to return. The default is to return all fields. + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1DNSEvent -Start (Get-Date).AddDays(-7) @@ -75,6 +78,10 @@ .FUNCTIONALITY Logs #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [String]$Query, [String]$IP, @@ -98,9 +105,10 @@ [datetime]$End = $(Get-Date), [String[]]$Fields, [int]$Limit = 100, - [int]$Offset = 0 + [int]$Offset = 0, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $StartEpoch = [math]::round($((Get-Date -Date ($Start) -UFormat %s))) $EndEpoch = [math]::round($((Get-Date -Date ($End) -UFormat %s))) @@ -174,9 +182,11 @@ $Filter = ConvertTo-QueryString($Filters) } Write-DebugMsg -Filters $Filters - if ($Filter) { - Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/dnsdata/v2/dns_event$Filter" | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue -WarningAction SilentlyContinue - } else { - Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/dnsdata/v2/dns_event" | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if($PSCmdlet.ShouldProcess("Query the DNS Security Logs","Query the DNS Security Logs",$MyInvocation.MyCommand)){ + if ($Filter) { + Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/dnsdata/v2/dns_event$Filter" | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } else { + Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/dnsdata/v2/dns_event" | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DNSLog.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DNSLog.ps1 index 1e9c247f..5f29ab58 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DNSLog.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DNSLog.ps1 @@ -42,6 +42,9 @@ .PARAMETER Offset Use this parameter to offset the results by the value entered for the purpose of pagination. Only works if -Limit is less than 10,000 and combined Limit and Offset do not exceed 10,000 + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1DNSLog -IP "10.10.172.35" -Query "google.com" -Type "A" -Response "216.58.201.110" -Start (Get-Date).AddHours(-6) -End (Get-Date) -Limit 1000 -Offset 0 @@ -54,6 +57,10 @@ .FUNCTIONALITY Logs #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [string]$Query, [string[]]$IP, @@ -68,9 +75,10 @@ [datetime]$End = (Get-Date), [ValidateRange(1,50000)] [int]$Limit = 100, - [int]$Offset = 0 + [int]$Offset = 0, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $Cube = 'NstarDnsActivity' if ($Limit -ge 10001) { @@ -165,22 +173,24 @@ $Data = $splat | ConvertTo-Json -Depth 4 -Compress $Query = [System.Web.HTTPUtility]::UrlEncode($Data) - if ($UseExport) { - $Options = '{"output":"csv","header":{"enabled":true,"display":["timestamp","query","response","query_type","dns_view","device_ip","mac_address","dhcp_fingerprint","name","query_nanosec"]}}' - Write-DebugMsg -Query ($splat | ConvertTo-Json -Depth 4) - $Result = Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/api/cubejs/v1/export?query=$Query&options=$Options" - $ResultData = ConvertFrom-Csv $Result - if ($ResultData) { - $ResultData - } else { - Write-Host "Error: No DNS logs returned." -ForegroundColor Red - } - } else { - $Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order - if ($Result) { - return $Result | Select-Object @{name="dns_server";Expression={$siteId = $_.'site_id'; (@($DNSServices).where({ $_.site_id -eq $siteId })).name}},* + if($PSCmdlet.ShouldProcess("Query the DNS Logs","Query the DNS Logs",$MyInvocation.MyCommand)){ + if ($UseExport) { + $Options = '{"output":"csv","header":{"enabled":true,"display":["timestamp","query","response","query_type","dns_view","device_ip","mac_address","dhcp_fingerprint","name","query_nanosec"]}}' + Write-DebugMsg -Query ($splat | ConvertTo-Json -Depth 4) + $Result = Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/api/cubejs/v1/export?query=$Query&options=$Options" + $ResultData = ConvertFrom-Csv $Result + if ($ResultData) { + $ResultData + } else { + Write-Host "Error: No DNS logs returned." -ForegroundColor Red + } } else { - Write-Host "Error: No DNS logs returned." -ForegroundColor Red + $Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order + if ($Result) { + return $Result | Select-Object @{name="dns_server";Expression={$siteId = $_.'site_id'; (@($DNSServices).where({ $_.site_id -eq $siteId })).name}},* + } else { + Write-Host "Error: No DNS logs returned." -ForegroundColor Red + } } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DiagnosticTask.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DiagnosticTask.ps1 index 7e3687b8..9a6f1d58 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DiagnosticTask.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DiagnosticTask.ps1 @@ -12,6 +12,9 @@ .PARAMETER download This switch indicates if to download the results returned + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1DiagnosticTask -id diagnostic/task/abcde634-2113-ddef-4d05-d35ffs1sa4 -download @@ -21,22 +24,30 @@ .FUNCTIONALITY Tasks #> - param( - [Parameter(Mandatory=$true)] - [String]$id, - [Switch]$download - ) - - if ($download) { - $URI = "https://csp.infoblox.com/atlas-onprem-diagnostic-service/v1/task/$($id)/download" - $Result = Invoke-CSP -Method GET -Uri $URI - } else { - $URI = "https://csp.infoblox.com/atlas-onprem-diagnostic-service/v1/task/$($id)" - $Result = Invoke-CSP -Method GET -Uri $URI | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue - } - Write-DebugMsg -URI $URI - - if ($Result) { - return $Result - } + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] + param( + [Parameter(Mandatory=$true)] + [String]$id, + [Switch]$Download, + [Switch]$Force + ) + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters + if ($download) { + if($PSCmdlet.ShouldProcess("$($id)","Download the diagnostic task results")){ + $URI = "https://csp.infoblox.com/atlas-onprem-diagnostic-service/v1/task/$($id)/download" + $Result = Invoke-CSP -Method GET -Uri $URI + } + } else { + if($PSCmdlet.ShouldProcess("$($id)","Get the diagnostic task details")){ + $URI = "https://csp.infoblox.com/atlas-onprem-diagnostic-service/v1/task/$($id)" + $Result = Invoke-CSP -Method GET -Uri $URI | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue + } + } + + if ($Result) { + return $Result + } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Export.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Export.ps1 index 133a50ee..30226829 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Export.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Export.ps1 @@ -12,6 +12,9 @@ .PARAMETER filePath The local file path where the export should be downloaded to + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1Export -data_ref (Get-B1BulkOperation -Name "Backup of all CSP data").data_ref -filePath "C:\Backups" @@ -34,6 +37,10 @@ .FUNCTIONALITY Backup #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [Parameter( ValueFromPipelineByPropertyName = $true, @@ -41,13 +48,17 @@ )] [string]$data_ref, [Parameter(Mandatory=$true)] - [string]$filePath + [string]$filePath, + [Switch]$Force ) process { - $B1Export = Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/storage?data_ref=$data_ref&direction=download" - if ($B1Export.result.url) { - $JSON = Invoke-RestMethod -Uri $B1Export.result.url - $JSON.data | ConvertTo-Json -Depth 15 | Out-File $filePath -Force -Encoding utf8 + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters + if($PSCmdlet.ShouldProcess($data_ref,"Get BloxOne Data Export")){ + $B1Export = Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/storage?data_ref=$data_ref&direction=download" + if ($B1Export.result.url) { + $JSON = Invoke-RestMethod -Uri $B1Export.result.url + $JSON.data | ConvertTo-Json -Depth 15 | Out-File $filePath -Force -Encoding utf8 + } } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Licenses.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Licenses.ps1 index c66b74a4..011e2d91 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Licenses.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Licenses.ps1 @@ -9,6 +9,9 @@ .PARAMETER State Use the -State parameter to filter by license state. (all/active/expired) + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1Licenses -State all @@ -21,10 +24,16 @@ .FUNCTIONALITY Licenses #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [ValidateSet('all','active','expired')] - [String]$State = "all" + [String]$State = "all", + [Switch]$Force ) + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $QueryFilters = @() if ($State) { $QueryFilters += "state=$($State)" @@ -33,11 +42,13 @@ $QueryString = ConvertTo-QueryString($QueryFilters) } - $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/licensing/v1/licenses$QueryString" | Select-Object -ExpandProperty results -EA SilentlyContinue -WA SilentlyContinue + if($PSCmdlet.ShouldProcess("List BloxOne Licenses","List BloxOne Licenses",$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/licensing/v1/licenses$QueryString" | Select-Object -ExpandProperty results -EA SilentlyContinue -WA SilentlyContinue - if ($Results) { - return $Results - } else { - Write-Host "Error. No BloxOne Licenses found." -ForegroundColor Red + if ($Results) { + return $Results + } else { + Write-Host "Error. No BloxOne Licenses found." -ForegroundColor Red + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Location.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Location.ps1 index 240ab330..77791c37 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Location.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Location.ps1 @@ -58,6 +58,9 @@ .PARAMETER id The id of the Location to filter by + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1Location -Name "Madrid" @@ -74,6 +77,10 @@ .FUNCTIONALITY BloxOneDDI #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [String]$Name, [String]$Description, @@ -91,9 +98,10 @@ [String]$OrderBy, [String]$OrderByTag, $CustomFilters, - [String]$id + [String]$id, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $MatchType = Match-Type $Strict [System.Collections.ArrayList]$Filters = @() @@ -155,10 +163,11 @@ Write-DebugMsg -Filters $QueryFilters - $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/infra/v1/locations$CombinedFilter" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if($PSCmdlet.ShouldProcess("List Locations","List Locations",$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/infra/v1/locations$CombinedFilter" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue - if ($Results) { - return $Results + if ($Results) { + return $Results + } } - } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1SecurityLog.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1SecurityLog.ps1 index 3c097705..3e7a219e 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1SecurityLog.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1SecurityLog.ps1 @@ -43,6 +43,9 @@ .PARAMETER Raw Return results as raw without additional parsing + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1SecurityLog -Limit "25" -Offset "0" -Username "my.email@domain.com" -App "nginx" -Type "nginx.access" -Domain "domain.com" @@ -52,6 +55,10 @@ .FUNCTIONALITY Logs #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [string]$Username, [string]$ClientIP, @@ -64,9 +71,10 @@ [Int]$Offset, [switch]$Strict, $CustomFilters, - [switch]$Raw + [switch]$Raw, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $Start = $Start.ToUniversalTime() $End = $End.ToUniversalTime() @@ -112,19 +120,21 @@ $QueryString = ConvertTo-QueryString $QueryFilters } Write-DebugMsg -Filters $QueryFilters - if ($QueryString) { - $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/security-events/v1/security_events$($QueryString)" -Method GET | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue - } else { - $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/security-events/v1/security_events" -Method GET | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue - } - if ($Results) { - if ($Raw) { - return $Results + if($PSCmdlet.ShouldProcess("Query the CSP Security Logs","Query the CSP Security Logs",$MyInvocation.MyCommand)){ + if ($QueryString) { + $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/security-events/v1/security_events$($QueryString)" -Method GET | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + } else { + $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/security-events/v1/security_events" -Method GET | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + } + if ($Results) { + if ($Raw) { + return $Results + } else { + $Results.log | ConvertFrom-Json | ConvertFrom-Json + } } else { - $Results.log | ConvertFrom-Json | ConvertFrom-Json + Write-Host "Error. Unable to find any security logs." -ForegroundColor Red + break } - } else { - Write-Host "Error. Unable to find any security logs." -ForegroundColor Red - break } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1ServiceLog.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1ServiceLog.ps1 index dc2a5af8..dfa4f227 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1ServiceLog.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1ServiceLog.ps1 @@ -24,6 +24,9 @@ .PARAMETER Offset Use this parameter to offset the results by the value entered for the purpose of pagination + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1ServiceLog -B1Host "bloxoneddihost1.mydomain.corp" -Container "DNS" -Start (Get-Date).AddHours(-2) @@ -33,6 +36,10 @@ .FUNCTIONALITY Logs #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [Alias('OnPremHost')] [string]$B1Host, @@ -40,9 +47,10 @@ [datetime]$Start = (Get-Date).AddDays(-1), [datetime]$End = (Get-Date), [Int]$Limit = 100, - [Int]$Offset + [Int]$Offset, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $Start = $Start.ToUniversalTime() $End = $End.ToUniversalTime() @@ -76,16 +84,18 @@ $QueryFilters = ConvertTo-QueryString -Filters $Filters Write-DebugMsg -Filters $Filters - $B1Hosts = Get-B1Host -Detailed - if ($QueryFilters) { - $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/atlas-logs/v1/logs$QueryFilters" -Method GET - } else { - $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/atlas-logs/v1/logs" -Method GET - } - if ($Results) { - return $Results.logs | Select-Object timestamp,@{Name = 'B1Host'; Expression = {$ophid = $_.ophid; (@($B1Hosts).where({ $_.ophid -eq $ophid })).display_name }},container_name,msg,ophid -ErrorAction SilentlyContinue - } else { - Write-Host "Error. Unable to find any service logs." -ForegroundColor Red - break + if($PSCmdlet.ShouldProcess("Query the BloxOne Services Logs","Query the BloxOne Services Logs",$MyInvocation.MyCommand)){ + $B1Hosts = Get-B1Host -Detailed -Fields ohpid,display_name -Limit 2500 + if ($QueryFilters) { + $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/atlas-logs/v1/logs$QueryFilters" -Method GET + } else { + $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/atlas-logs/v1/logs" -Method GET + } + if ($Results) { + return $Results.logs | Select-Object timestamp,@{Name = 'B1Host'; Expression = {$ophid = $_.ophid; (@($B1Hosts).where({ $_.ophid -eq $ophid })).display_name }},container_name,msg,ophid -ErrorAction SilentlyContinue + } else { + Write-Host "Error. Unable to find any service logs." -ForegroundColor Red + break + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Tag.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Tag.ps1 index 9010318a..3eb6880f 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Tag.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Tag.ps1 @@ -28,6 +28,9 @@ Accepts either an Object, ArrayList or String containing one or more custom filters. See here for usage: https://ibps.readthedocs.io/en/latest/#-customfilters + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1Tag -Name "siteCode" @@ -37,6 +40,10 @@ .FUNCTIONALITY Tags #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [String]$Name, [ValidateSet("active","revoked")] @@ -45,8 +52,10 @@ [String[]]$Fields, [Int]$Limit = 100, [Int]$Offset, - $CustomFilters + $CustomFilters, + [Switch]$Force ) + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $MatchType = Match-Type $Strict [System.Collections.ArrayList]$Filters = @() [System.Collections.ArrayList]$QueryFilters = @() @@ -78,9 +87,11 @@ $QueryString = ConvertTo-QueryString $QueryFilters } Write-DebugMsg -Filters $QueryFilters - if ($QueryString) { - Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/atlas-tagging/v2/tags$($QueryString)" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue - } else { - Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/atlas-tagging/v2/tags" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + if($PSCmdlet.ShouldProcess("List Tags","List Tags",$MyInvocation.MyCommand)){ + if ($QueryString) { + Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/atlas-tagging/v2/tags$($QueryString)" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + } else { + Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/api/atlas-tagging/v2/tags" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1User.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1User.ps1 index c55bfee1..1cd20491 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1User.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1User.ps1 @@ -40,6 +40,9 @@ .PARAMETER id The id of the authoritative zone to filter by + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1User -Name "MyName" @@ -55,6 +58,10 @@ .FUNCTIONALITY Authentication #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [String]$Name, [String]$Email, @@ -68,9 +75,10 @@ [String[]]$Fields, [String]$OrderBy, $CustomFilters, - [String]$id + [String]$id, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $MatchType = Match-Type $Strict [System.Collections.ArrayList]$Filters = @() [System.Collections.ArrayList]$QueryFilters = @() @@ -113,13 +121,14 @@ $QueryString = ConvertTo-QueryString $QueryFilters } Write-DebugMsg -Filters $QueryFilters - if ($QueryString) { - $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/users$($QueryString)" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue - } else { - $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/users" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + if($PSCmdlet.ShouldProcess("List Users","List Users",$MyInvocation.MyCommand)){ + if ($QueryString) { + $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/users$($QueryString)" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + } else { + $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/users" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + } + if ($Results) { + return $Results + } } - if ($Results) { - return $Results - } - } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1UserAPIKey.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1UserAPIKey.ps1 index 4c04af30..65d81a66 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1UserAPIKey.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1UserAPIKey.ps1 @@ -32,6 +32,9 @@ .PARAMETER id The id of the authoritative zone to filter by + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Get-B1UserAPIKey -Name "somename" -State Enabled @@ -44,6 +47,10 @@ .FUNCTIONALITY Authentication #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [String]$Name, [ValidateSet("Enabled", "Disabled")] @@ -53,9 +60,10 @@ [Switch]$Strict, [String[]]$Fields, $CustomFilters, - [String]$id + [String]$id, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $MatchType = Match-Type $Strict [System.Collections.ArrayList]$Filters = @() [System.Collections.ArrayList]$QueryFilters = @() @@ -89,14 +97,15 @@ $QueryString = ConvertTo-QueryString $QueryFilters } Write-DebugMsg -Filters $QueryFilters - if ($QueryString) { - $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_api_keys$($QueryString)" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue - } else { - $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_api_keys" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + if($PSCmdlet.ShouldProcess("List User API Keys","List User API Keys",$MyInvocation.MyCommand)){ + if ($QueryString) { + $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_api_keys$($QueryString)" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + } else { + $Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_api_keys" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue + } + + if ($Results) { + return $Results + } } - - if ($Results) { - return $Results - } - } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/New-B1APIKey.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/New-B1APIKey.ps1 index a8fc2e8f..4965b8d0 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/New-B1APIKey.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/New-B1APIKey.ps1 @@ -27,6 +27,9 @@ .PARAMETER Expires The date/time when the key will expire. Defaults to 1 year. + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Medium. + .EXAMPLE New-B1APIKey -Name "somename" -Type Interactive @@ -39,12 +42,17 @@ .FUNCTIONALITY Authentication #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Medium' + )] param( [ValidateSet("Interactive", "Service")] [String]$Type, [Parameter(Mandatory=$true)] [String]$Name, - [DateTime]$Expires = $(Get-Date).AddYears(1) + [DateTime]$Expires = $(Get-Date).AddYears(1), + [Switch]$Force ) DynamicParam { @@ -73,19 +81,20 @@ $paramDictionary.Add('UserName', $userNameParam) return $paramDictionary } - } + } process { + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $ExpiresAt = Get-Date $Expires -Format o switch($Type) { "Service" { $UserEmail = $PSBoundParameters['UserEmail'] $UserName = $PSBoundParameters['UserName'] - $ExistingAPIKey = Get-B1APIKey -Name $Name -User $UserEmail -Type Service + $ExistingAPIKey = Get-B1APIKey -Name $Name -User $UserEmail -Type Service -Confirm:$false if ($UserEmail) { - $AttachUser = Get-B1User -Email $UserEmail -Strict -Type Service + $AttachUser = Get-B1User -Email $UserEmail -Strict -Type Service -Confirm:$false } elseif ($UserName) { - $AttachUser = Get-B1User -Name $UserName -Strict -Type Service + $AttachUser = Get-B1User -Name $UserName -Strict -Type Service -Confirm:$false } if ($AttachUser) { if ($AttachUser.count -gt 1) { @@ -108,10 +117,12 @@ "user_id" = $UserID "expires_at" = $ExpiresAt } | ConvertTo-Json -Depth 2 - $Results = Invoke-CSP -Method POST -Uri "$(Get-B1CSPUrl)/v2/api_keys" -Data $NewAPIKeyJson | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if($PSCmdlet.ShouldProcess($NewAPIKeyJson,"Create new BloxOne API Key",$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Method POST -Uri "$(Get-B1CSPUrl)/v2/api_keys" -Data $NewAPIKeyJson | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } } "Interactive" { - $ExistingAPIKey = Get-B1UserAPIKey -Name $Name -Strict + $ExistingAPIKey = Get-B1UserAPIKey -Name $Name -Strict -Confirm:$false if ($ExistingAPIKey) { Write-Error "Error. API Key: $($ExistingAPIKey.name) already exists." break @@ -120,18 +131,22 @@ "name" = $Name "expires_at" = $ExpiresAt } | ConvertTo-Json -Depth 2 - $Results = Invoke-CSP -Method POST -Uri "$(Get-B1CSPUrl)/v2/current_api_keys" -Data $NewAPIKeyJson | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + if($PSCmdlet.ShouldProcess($NewAPIKeyJson,"Create new BloxOne API Key",$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Method POST -Uri "$(Get-B1CSPUrl)/v2/current_api_keys" -Data $NewAPIKeyJson | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue -WarningAction SilentlyContinue + } } } - if ($Results) { - Write-Host "Successfully created API Key: $($Results.name)" -ForegroundColor Green - Write-Host "Your new API Key is: $($Results.key)" -ForegroundColor Cyan - Write-Host "Please ensure you copy this key somewhere safe, it is not retrievable again." -ForegroundColor Yellow - return $Results - } else { - Write-Error "Failed to create new API Key: $($Name)" - break + if($PSCmdlet.ShouldProcess($MyInvocation.MyCommand,'Results')){ + if ($Results) { + Write-Host "Successfully created API Key: $($Results.name)" -ForegroundColor Green + Write-Host "Your new API Key is: $($Results.key)" -ForegroundColor Cyan + Write-Host "Please ensure you copy this key somewhere safe, it is not retrievable again." -ForegroundColor Yellow + return $Results + } else { + Write-Error "Failed to create new API Key: $($Name)" + break + } } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/New-B1Location.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/New-B1Location.ps1 index 8f5f079c..3e75c5e3 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/New-B1Location.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/New-B1Location.ps1 @@ -36,6 +36,9 @@ .PARAMETER ContactPhone The contact phone number for the new location + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Medium. + .EXAMPLE PS> New-B1Location -Name "Madrid" -Description "Real Madrid Museum" -Address "Estadio Santiago Bernabeu Avenida Concha Espina" -PostCode "28036" -State "Madrid" -Country "Spain" -ContactName "Curator" -ContactEmail "Curator@realmadrid.com" @@ -58,6 +61,10 @@ .FUNCTIONALITY BloxOneDDI #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Medium' + )] param( [Parameter(Mandatory=$true)] [String]$Name, @@ -71,9 +78,10 @@ [String]$Country, [String]$ContactEmail, [String]$ContactName, - [String]$ContactPhone + [String]$ContactPhone, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $Splat = @{ "name" = $($Name) "address" = @{ @@ -194,10 +202,11 @@ $Splat.latitude = $GeoCode.latitude $JSON = $Splat | ConvertTo-Json -Depth 5 -Compress + if($PSCmdlet.ShouldProcess($(JSONPretty($JSON)),"Create new BloxOne Location",$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Method POST -Uri "$(Get-B1CSPUrl)/api/infra/v1/locations" -Data ([System.Text.Encoding]::UTF8.GetBytes($JSON)) - $Results = Invoke-CSP -Method POST -Uri "$(Get-B1CSPUrl)/api/infra/v1/locations" -Data ([System.Text.Encoding]::UTF8.GetBytes($JSON)) - - if ($Results) { - return $Results | Select-Object -ExpandProperty result + if ($Results) { + return $Results | Select-Object -ExpandProperty result + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Remove-B1APIKey.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Remove-B1APIKey.ps1 index cab5c9d4..d2b96c67 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Remove-B1APIKey.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Remove-B1APIKey.ps1 @@ -22,6 +22,9 @@ .PARAMETER id The id of the API Key. Accepts pipeline input + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will always prompt for confirmation unless -Confirm:$false or -Force is specified. + .EXAMPLE PS> Remove-B1APIKey -User "user@domain.corp" -Name "somename" -Type "interactive" -State Enabled @@ -34,6 +37,10 @@ .FUNCTIONALITY Authentication #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'High' + )] param( [Parameter(Mandatory=$true,ParameterSetName="Default")] $Name, @@ -50,34 +57,37 @@ ParameterSetName="With ID", Mandatory=$true )] - [String]$id + [String]$id, + [Switch]$Force ) process { + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters if ($id) { - $APIKey = Get-B1APIkey -id $id + $APIKey = Get-B1APIkey -id $id -Confirm:$false } else { if ($Type -and $State) { - $APIKey = Get-B1APIKey -User $User -Name $Name -Type $Type -State $State -Strict + $APIKey = Get-B1APIKey -User $User -Name $Name -Type $Type -State $State -Strict -Confirm:$false } elseif ($Type) { - $APIKey = Get-B1APIKey -User $User -Name $Name -Type $Type -Strict + $APIKey = Get-B1APIKey -User $User -Name $Name -Type $Type -Strict -Confirm:$false } elseif ($State) { - $APIKey = Get-B1APIKey -User $User -Name $Name -State $State -Strict + $APIKey = Get-B1APIKey -User $User -Name $Name -State $State -Strict -Confirm:$false } else { - $APIKey = Get-B1APIKey -User $User -Name $Name -Strict + $APIKey = Get-B1APIKey -User $User -Name $Name -Strict -Confirm:$false } } if ($APIKey) { if ($APIKey.count -eq 1) { $APIKeyIdSplit = $APIKey.id -split "identity/apikeys/" if ($APIKeyIdSplit[1]) { - - Invoke-CSP -Method DELETE -Uri "$(Get-B1CSPUrl)/v2/api_keys/$($APIKeyIdSplit[1])" - } - if (Get-B1APIkey -id $($APIKey.id)) { - Write-Error "Error. Failed to delete API Key: $($APIKey.name)" - } else { - Write-Host "Successfully deleted API Key: $($APIKey.name)" -ForegroundColor Green + if($PSCmdlet.ShouldProcess($($APIKeyIdSplit[1]))){ + Invoke-CSP -Method DELETE -Uri "$(Get-B1CSPUrl)/v2/api_keys/$($APIKeyIdSplit[1])" + if (Get-B1APIkey -id $($APIKey.id) -Confirm:$false) { + Write-Error "Error. Failed to delete API Key: $($APIKey.name)" + } else { + Write-Host "Successfully deleted API Key: $($APIKey.name)" -ForegroundColor Green + } + } } } else { Write-Error "More than one result returned. To remove multiple objects, pipe Get-B1APIKey into Remove-B1APIKey instead" diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Remove-B1Location.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Remove-B1Location.ps1 index 10f32a8b..a2433eed 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Remove-B1Location.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Remove-B1Location.ps1 @@ -12,6 +12,9 @@ .PARAMETER Object The Location Object. Accepts pipeline input from Get-B1Location + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will always prompt for confirmation unless -Confirm:$false or -Force is specified. + .EXAMPLE PS> Remove-B1Location -Name "Madrid" @@ -25,6 +28,10 @@ .FUNCTIONALITY BloxOneDDI #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'High' + )] param( [Parameter(Mandatory=$true,ParameterSetName="Default")] [String]$Name, @@ -33,10 +40,12 @@ ParameterSetName="Pipeline", Mandatory=$true )] - [System.Object]$Object + [System.Object]$Object, + [Switch]$Force ) process { + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters if (!($Object)) { $Object = Get-B1Location -Name $Name -Strict } @@ -48,11 +57,13 @@ } if ($Object.count -eq 1) { $ObjectID = ($Object.id -Split ('/'))[2] - $Results = Invoke-CSP -Method DELETE -Uri "$(Get-B1CSPUrl)/api/infra/v1/locations/$($ObjectID)" - if (Get-B1Location -id $($Object.id)) { - Write-Error "Error. Failed to delete Location: $($Object.name)" - } else { - Write-Host "Successfully deleted Location: $($Object.name)" -ForegroundColor Green + if($PSCmdlet.ShouldProcess($($ObjectID))){ + $Results = Invoke-CSP -Method DELETE -Uri "$(Get-B1CSPUrl)/api/infra/v1/locations/$($ObjectID)" + if (Get-B1Location -id $($Object.id)) { + Write-Error "Error. Failed to delete Location: $($Object.name)" + } else { + Write-Host "Successfully deleted Location: $($Object.name)" -ForegroundColor Green + } } } else { Write-Error "More than one result returned. To remove multiple objects, pipe Get-B1Location into Remove-B1Location instead" diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Search-B1.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Search-B1.ps1 index 21d00a18..3601b5d8 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Search-B1.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Search-B1.ps1 @@ -13,6 +13,9 @@ Use this parameter to include the query shard, aggregation, state, and duration data. By default, the hits property is auto-expanded + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Search-B1 "10.10.100.1" @@ -25,19 +28,26 @@ .FUNCTIONALITY Search #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [Parameter(Mandatory=$true)] [String]$Query, - [Switch]$IncludeQueryDetails + [Switch]$IncludeQueryDetails, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $Body = @{ "query"=$Query } | ConvertTo-Json | ForEach-Object { [System.Text.RegularExpressions.Regex]::Unescape($_)} - $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/atlas-search-api/v1/search" -Method "POST" -Data $Body - if ($IncludeQueryDetails) { - $Results - } else { - $Results.hits | Select-Object -ExpandProperty hits + if($PSCmdlet.ShouldProcess("Search BloxOne","Search BloxOne",$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/atlas-search-api/v1/search" -Method "POST" -Data $Body + if ($IncludeQueryDetails) { + $Results + } else { + $Results.hits | Select-Object -ExpandProperty hits + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Set-B1APIKey.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Set-B1APIKey.ps1 index 4c3ce51b..7fe763f0 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Set-B1APIKey.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Set-B1APIKey.ps1 @@ -21,6 +21,9 @@ .PARAMETER Object The API Key Object. Accepts pipeline input + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Medium. + .EXAMPLE PS> Set-B1APIKey -User "user@domain.corp" -Name "somename" -Type "interactive" -State Enabled @@ -30,6 +33,10 @@ .FUNCTIONALITY Authentication #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Medium' + )] param( [Parameter(Mandatory=$true,ParameterSetName="Default")] $Name, @@ -45,10 +52,12 @@ ParameterSetName="Object", Mandatory=$true )] - [System.Object]$Object + [System.Object]$Object, + [Switch]$Force ) process { + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters if ($Object) { $SplitID = $Object.id.split('/') if (("$($SplitID[0])/$($SplitID[1])") -ne "identity/apikeys") { @@ -79,11 +88,13 @@ } $JSON = $NewObj | ConvertTo-Json -Depth 5 -Compress - $Results = Invoke-CSP -Method PATCH -Uri "$(Get-B1CSPUrl)/v2/api_keys/$($APIKeyIdSplit[1])" -Data $JSON - if ($Results | Select-Object -ExpandProperty result -EA SilentlyContinue -WA SilentlyContinue) { - $Results | Select-Object -ExpandProperty result - } else { - $Results + if($PSCmdlet.ShouldProcess("Update BloxOne API Key`n$(JSONPretty($JSON))","Update BloxOne API Key: $($APIKeyIdSplit[1])",$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Method PATCH -Uri "$(Get-B1CSPUrl)/v2/api_keys/$($APIKeyIdSplit[1])" -Data $JSON + if ($Results | Select-Object -ExpandProperty result -EA SilentlyContinue -WA SilentlyContinue) { + $Results | Select-Object -ExpandProperty result + } else { + $Results + } } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Set-B1Location.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Set-B1Location.ps1 index 484ef8fe..3eb0a3f3 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Set-B1Location.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Set-B1Location.ps1 @@ -42,6 +42,9 @@ .PARAMETER Object The Location Object. Accepts pipeline input from Get-B1Location + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Medium. + .EXAMPLE PS> Get-B1Location -Name "Madrid" | Set-B1Location -NewName "Rome" -Description "Rome Office (Moved from Madrid)" -Address "1 Via Cavour" -PostCode "00184" -State "Rome" -Country "Italy" -ContactName "Curator" -ContactEmail "Curator@rome.com" @@ -80,7 +83,10 @@ .FUNCTIONALITY BloxOneDDI #> - [Parameter(ParameterSetName="Default",Mandatory=$true)] + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Medium' + )] param( [Parameter(ParameterSetName='Default',Mandatory=$true)] [String]$Name, @@ -99,10 +105,12 @@ ParameterSetName="Pipeline", Mandatory=$true )] - [System.Object]$Object + [System.Object]$Object, + [Switch]$Force ) process { + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters if ($Object) { $SplitID = $Object.id.split('/') if (("$($SplitID[0])/$($SplitID[1])") -ne "infra/location") { @@ -240,10 +248,11 @@ $JSON = $Object | Select-Object * -ExcludeProperty id,updated_at,created_at | ConvertTo-Json -Depth 5 -Compress $ObjectID = ($Object.id -Split ('/'))[2] - $Results = Invoke-CSP -Method PUT -Uri "$(Get-B1CSPUrl)/api/infra/v1/locations/$($ObjectID)" -Data ([System.Text.Encoding]::UTF8.GetBytes($JSON)) - - if ($Results) { - return $Results | Select-Object -ExpandProperty result + if($PSCmdlet.ShouldProcess("Update BloxOne Location`n$(JSONPretty($JSON))","Update BloxOne Location: $($ObjectID)",$MyInvocation.MyCommand)){ + $Results = Invoke-CSP -Method PUT -Uri "$(Get-B1CSPUrl)/api/infra/v1/locations/$($ObjectID)" -Data ([System.Text.Encoding]::UTF8.GetBytes($JSON)) + if ($Results) { + return $Results | Select-Object -ExpandProperty result + } } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Start-B1Export.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Start-B1Export.ps1 index 91c91ccf..e1fc694c 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Start-B1Export.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOneCloud/Start-B1Export.ps1 @@ -45,6 +45,9 @@ .PARAMETER BackupAll Use this switch to enable all configuration & data types to be included in the export/backup + .PARAMETER Force + Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low. + .EXAMPLE PS> Start-B1Export -Name "Backup" -Description "Backup of all CSP data" -DNSConfig -DNSData -IPAMData -KeyData -ThreatDefense -Bootstrap -B1Hosts -Redirects -Tags @@ -67,6 +70,10 @@ .FUNCTIONALITY Backup #> + [CmdletBinding( + SupportsShouldProcess, + ConfirmImpact = 'Low' + )] param( [Parameter(Mandatory=$true)] [String]$Name, @@ -82,9 +89,10 @@ [Switch]$B1Hosts, [Switch]$Redirects, [Switch]$Tags, - [Switch]$BackupAll + [Switch]$BackupAll, + [Switch]$Force ) - + $ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters $splat = @{ "name" = $Name "description" = $Description @@ -152,11 +160,12 @@ $splat | Add-Member -Name "data_types" -Value $dataTypes -MemberType NoteProperty } $splat = $splat | ConvertTo-Json - $Export = Invoke-CSP -Method "POST" -Uri "$(Get-B1CSPUrl)/bulk/v1/export" -Data $splat - - if ($Export.success.message -eq "Export pending") { - Write-Host "Data Export initalised successfully." -ForegroundColor Green - } else { - Write-Host "Data Export failed to initialise." -ForegroundColor Red + if($PSCmdlet.ShouldProcess("Start BloxOne Data Export`n$(JSONPretty($splat))","Start BloxOne Data Export",$MyInvocation.MyCommand)){ + $Export = Invoke-CSP -Method "POST" -Uri "$(Get-B1CSPUrl)/bulk/v1/export" -Data $splat + if ($Export.success.message -eq "Export pending") { + Write-Host "Data Export initalised successfully." -ForegroundColor Green + } else { + Write-Host "Data Export failed to initialise." -ForegroundColor Red + } } } \ No newline at end of file diff --git a/Modules/ibPS/Functions/BloxOne/BloxOnePlatform/Start-B1DiagnosticTask.ps1 b/Modules/ibPS/Functions/BloxOne/BloxOnePlatform/Start-B1DiagnosticTask.ps1 index e8a9d9c0..d2c0adcf 100644 --- a/Modules/ibPS/Functions/BloxOne/BloxOnePlatform/Start-B1DiagnosticTask.ps1 +++ b/Modules/ibPS/Functions/BloxOne/BloxOnePlatform/Start-B1DiagnosticTask.ps1 @@ -151,16 +151,16 @@ $Result = Invoke-CSP -Method POST -Uri "$(Get-B1CSPUrl)/atlas-onprem-diagnostic-service/v1/task" -Data $splat | Select-Object -ExpandProperty result -ErrorAction SilentlyContinue if ($Result) { if ($WaitForOutput) { - while ((Get-B1DiagnosticTask -id $Result.id).status -eq "InProgress") { + while ((Get-B1DiagnosticTask -id $Result.id -Confirm:$false).status -eq "InProgress") { Write-Host "Waiting for task to complete on $($OPH.display_name).." -ForegroundColor Yellow Wait-Event -Timeout 5 } if ($DNSConfiguration) { - $Job = Get-B1DiagnosticTask -id $Result.id -Download + $Job = Get-B1DiagnosticTask -id $Result.id -Download -Confirm:$false } elseif ($DHCPConfiguration) { - $Job = Get-B1DiagnosticTask -id $Result.id -Download | Select-Object -ExpandProperty Dhcp4 -ErrorAction SilentlyContinue + $Job = Get-B1DiagnosticTask -id $Result.id -Download -Confirm:$false | Select-Object -ExpandProperty Dhcp4 -ErrorAction SilentlyContinue } else { - $Job = Get-B1DiagnosticTask -id $Result.id + $Job = Get-B1DiagnosticTask -id $Result.id -Confirm:$false } if ($Job) { return $Job diff --git a/Modules/ibPS/Functions/Misc/Misc.ps1 b/Modules/ibPS/Functions/Misc/Misc.ps1 index 05f248d2..cbe12acb 100644 --- a/Modules/ibPS/Functions/Misc/Misc.ps1 +++ b/Modules/ibPS/Functions/Misc/Misc.ps1 @@ -908,6 +908,8 @@ function DevelopmentFunctions { "Initialize-B1Config" "Write-Chart" "Write-Graph" + "Confirm-ShouldProcess" + "JSONPretty" ) } @@ -1022,4 +1024,22 @@ function Write-Chart { $(1..$($Map.Count) | ForEach-Object { Write-Host -NoNewline "$($UnderChar)$($UnderChar)$($UnderChar)$($UnderChar)$($UnderChar)$([char]9516)$($UnderChar)$($UnderChar)$($UnderChar)$($UnderChar)" }) Write-Host "" Write-Graph -YAxisLabel ' ' -Row " $($DateStrings -join " $([char]9474) ")" -RowColor Black -LabelColor 'Blue' +} + +function Confirm-ShouldProcess { + param( + [Parameter(Mandatory=$true)] + [System.Object]$Params + ) + + if ($Params.Force -and -not $Params.Confirm){ + $Pref = 'None' + return $Pref + } else { + return $ConfirmPreference + } +} + +function JSONPretty($JSON) { + $JSON | ConvertFrom-Json | ConvertTo-Json -Depth 20 } \ No newline at end of file diff --git a/RELEASE.md b/RELEASE.md index e92477ab..c6e0c28e 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -2,4 +2,29 @@ - Add `Get-B1RPZFeed` function - Add new CubeJS wrapper functions for interacting with the BloxOne CubeJS API - Add `-VMHost` parameter to `Deploy-B1Appliance` when using `-Type VMware`. This is used both to specify a specific host on a Cluster, or on its own to enable support for deploying to standalone hosts. -- Various minor code improvements & fixes \ No newline at end of file +- Various minor code improvements & fixes + +### Breaking Changes +Support for `ShouldProcess` is being added for all functions, which enables three new parameters. `-Confirm`, `-WhatIf` & `-Force`. +The default PowerShell configuration has `$ConfirmPreference` set to **High**. Unless you have changed this, only `Remove` operations will be impacted by this change. + +- All `Get` and equivilent read commands are set to `ConfirmImpact=Low`. + - These commands will not prompt for confirmation if `$ConfirmPreference` is None, Medium or High. +- All `Set` and equivilent update commands are set to `ConfirmImpact=Medium`. + - These commands will not prompt for confirmation if `$ConfirmPreference` is None or High. +- All `New` and equivilent new commands are set to `ConfirmImpact=Medium`. + - These commands will not prompt for confirmation if `$ConfirmPreference` is None or High. +- All `Remove` and equivilent destroy commands are set to `ConfirmImpact=High` + - These commands **will** prompt for confirmation unless `$ConfirmPreference` is set to None. + +A handy reference table has been included below; + +| Operation Type | Confirm Impact | No Prompt When | +|:---------------------------|:---------------------------|:---------------------------| +| `Get` | `Low` | `None`, `Medium`, `High` | +| `Set` | `Medium` | `None`, `High` | +| `New` | `Medium` | `None`, `High` | +| `Remove` | `High` | `None` | + +You can check your current preference by running `$ConfirmPreference` in your terminal. +See here for more information on [Preference Variables](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_preference_variables?view=powershell-7.4#confirmpreference) \ No newline at end of file