Skip to content

Commit

Permalink
Add default filter to retrieve tickets from the past week for Get-AzS…
Browse files Browse the repository at this point in the history
…upportTickets and Get-AzSupportTicketsNoSubscription (#10)

* add custom filtering for list support ticket if no filter is applied
  • Loading branch information
grhuangmsft authored Mar 15, 2024
1 parent 615e1c5 commit 112512e
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 73 deletions.
8 changes: 8 additions & 0 deletions src/Support/Support.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ directive:
verb: New
subject: FilesNoSubscription
hide: true
- where:
verb: Get
subject: SupportTicket
hide: true
- where:
verb: Get
subject: SupportTicketsNoSubscription
hide: true
- where:
verb: Update
subject: File
Expand Down

This file was deleted.

139 changes: 139 additions & 0 deletions src/Support/Support.Autorest/custom/Get-AzSupportTicket.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@

# ----------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
# is regenerated.
# ----------------------------------------------------------------------------------

<#
.Synopsis
Get ticket details for an Azure subscription.
Support ticket data is available for 18 months after ticket creation.
If a ticket was created more than 18 months ago, a request for data might cause an error.
If no parameters are specified, then this command will retrieve all tickets created in the last week by default.
.Description
Get ticket details for an Azure subscription.
Support ticket data is available for 18 months after ticket creation.
If a ticket was created more than 18 months ago, a request for data might cause an error.
If no parameters are specified, then this command will retrieve all tickets created in the last week by default.
.Example
{{ Add code here }}
.Example
{{ Add code here }}
.Outputs
Microsoft.Azure.PowerShell.Cmdlets.Support.Models.ISupportTicketDetails
.Link
https://learn.microsoft.com/powershell/module/az.support/get-azsupportticket
#>
function Get-AzSupportTicket {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.Support.Models.ISupportTicketDetails])]
[CmdletBinding(DefaultParameterSetName='List', PositionalBinding=$false)]
param(
[Parameter(ParameterSetName='Get', Mandatory)]
[Alias('SupportTicketName')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Path')]
[System.String]
# Support ticket name.
${Name},

[Parameter(ParameterSetName='Get')]
[Parameter(ParameterSetName='List')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
[System.String[]]
# Azure subscription Id.
${SubscriptionId},

[Parameter(ParameterSetName='GetViaIdentity', Mandatory, ValueFromPipeline)]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Models.ISupportIdentity]
# Identity Parameter
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
${InputObject},

[Parameter(ParameterSetName='List')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Query')]
[System.String]
# The filter to apply on the operation.
# We support 'odata v4.0' filter semantics.
# [Learn more](https://docs.microsoft.com/odata/concepts/queryoptions-overview).
# _Status_, _ServiceId_, and _ProblemClassificationId_ filters can only be used with Equals ('eq') operator.
# For _CreatedDate_ filter, the supported operators are Greater Than ('gt') and Greater Than or Equals ('ge').
# When using both filters, combine them using the logical 'AND'.
${Filter},

[Parameter(ParameterSetName='List')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Query')]
[System.Int32]
# The number of values to return in the collection.
# Default is 25 and max is 100.
${Top},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Azure')]
[System.Management.Automation.PSObject]
# The DefaultProfile parameter is not functional.
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
${DefaultProfile},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Wait for .NET debugger to attach
${Break},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be appended to the front of the pipeline
${HttpPipelineAppend},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
${HttpPipelinePrepend},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[System.Uri]
# The URI for the proxy server to use
${Proxy},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[System.Management.Automation.PSCredential]
# Credentials for a proxy server to use for the remote call
${ProxyCredential},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Use the default credentials for the proxy
${ProxyUseDefaultCredentials}
)

process {
If($PSCmdlet.ParameterSetName -eq 'List' -and !$PSBoundParameters.ContainsKey('Top') -and !$PSBoundParameters.ContainsKey('Filter')){
$OneWeekAgo = (Get-Date).AddDays(-7).ToString("yyyy-MM-ddTHH:mm:ssZ")
$Filter = "CreatedDate ge $($OneWeekAgo)"
$PSBoundParameters.Add('Filter', $Filter)
}
Az.Support.internal\Get-AzSupportTicket @PSBoundParameters
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@

# ----------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
# is regenerated.
# ----------------------------------------------------------------------------------

<#
.Synopsis
Gets details for a specific support ticket.
Support ticket data is available for 18 months after ticket creation.
If a ticket was created more than 18 months ago, a request for data might cause an error.
If no parameters are specified, then this command will retrieve all tickets created in the last week by default.
.Description
Gets details for a specific support ticket.
Support ticket data is available for 18 months after ticket creation.
If a ticket was created more than 18 months ago, a request for data might cause an error.
If no parameters are specified, then this command will retrieve all tickets created in the last week by default.
.Example
{{ Add code here }}
.Example
{{ Add code here }}
.Outputs
Microsoft.Azure.PowerShell.Cmdlets.Support.Models.IFileDetails
.Link
https://learn.microsoft.com/powershell/module/az.support/get-azsupportticketsnosubscription
#>
function Get-AzSupportTicketsNoSubscription {
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.Support.Models.ISupportTicketDetails])]
[CmdletBinding(DefaultParameterSetName='List', PositionalBinding=$false)]
param(
[Parameter(ParameterSetName='Get', Mandatory)]
[Alias('Name')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Path')]
[System.String]
# Support ticket name.
${SupportTicketName},

[Parameter(ParameterSetName='GetViaIdentity', Mandatory, ValueFromPipeline)]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Path')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Models.ISupportIdentity]
# Identity Parameter
# To construct, see NOTES section for INPUTOBJECT properties and create a hash table.
${InputObject},

[Parameter(ParameterSetName='List')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Query')]
[System.String]
# The filter to apply on the operation.
# We support 'odata v4.0' filter semantics.
# <a target='_blank' href='https://docs.microsoft.com/odata/concepts/queryoptions-overview'>Learn more</a> <br/><i>Status</i> , <i>ServiceId</i>, and <i>ProblemClassificationId</i> filters can only be used with 'eq' operator.
# For <i>CreatedDate</i> filter, the supported operators are 'gt' and 'ge'.
# When using both filters, combine them using the logical 'AND'.
${Filter},

[Parameter(ParameterSetName='List')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Query')]
[System.Int32]
# The number of values to return in the collection.
# Default is 25 and max is 100.
${Top},

[Parameter()]
[Alias('AzureRMContext', 'AzureCredential')]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Azure')]
[System.Management.Automation.PSObject]
# The DefaultProfile parameter is not functional.
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
${DefaultProfile},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Wait for .NET debugger to attach
${Break},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be appended to the front of the pipeline
${HttpPipelineAppend},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.SendAsyncStep[]]
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
${HttpPipelinePrepend},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[System.Uri]
# The URI for the proxy server to use
${Proxy},

[Parameter(DontShow)]
[ValidateNotNull()]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[System.Management.Automation.PSCredential]
# Credentials for a proxy server to use for the remote call
${ProxyCredential},

[Parameter(DontShow)]
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
[System.Management.Automation.SwitchParameter]
# Use the default credentials for the proxy
${ProxyUseDefaultCredentials}
)

process {
If($PSCmdlet.ParameterSetName -eq 'List' -and !$PSBoundParameters.ContainsKey('Top') -and !$PSBoundParameters.ContainsKey('Filter')){
$OneWeekAgo = (Get-Date).AddDays(-7).ToString("yyyy-MM-ddTHH:mm:ssZ")
$Filter = "CreatedDate ge $($OneWeekAgo)"
$PSBoundParameters.Add('Filter', $Filter)
}
Az.Support.internal\Get-AzSupportTicketsNoSubscription @PSBoundParameters
}
}
2 changes: 2 additions & 0 deletions src/Support/Support.Autorest/docs/Az.Support.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ Gets a specific Azure service for support ticket creation.
Get ticket details for an Azure subscription.
Support ticket data is available for 18 months after ticket creation.
If a ticket was created more than 18 months ago, a request for data might cause an error.
If no parameters are specified, then this command will retrieve all tickets created in the last week by default.

### [Get-AzSupportTicketsNoSubscription](Get-AzSupportTicketsNoSubscription.md)
Gets details for a specific support ticket.
Support ticket data is available for 18 months after ticket creation.
If a ticket was created more than 18 months ago, a request for data might cause an error.
If no parameters are specified, then this command will retrieve all tickets created in the last week by default.

### [New-AzSupportCommunication](New-AzSupportCommunication.md)
Adds a new customer communication to an Azure support ticket.
Expand Down
5 changes: 4 additions & 1 deletion src/Support/Support.Autorest/docs/Get-AzSupportTicket.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ schema: 2.0.0
Get ticket details for an Azure subscription.
Support ticket data is available for 18 months after ticket creation.
If a ticket was created more than 18 months ago, a request for data might cause an error.
If no parameters are specified, then this command will retrieve all tickets created in the last week by default.

## SYNTAX

Expand All @@ -35,6 +36,7 @@ Get-AzSupportTicket -InputObject <ISupportIdentity> [-DefaultProfile <PSObject>]
Get ticket details for an Azure subscription.
Support ticket data is available for 18 months after ticket creation.
If a ticket was created more than 18 months ago, a request for data might cause an error.
If no parameters are specified, then this command will retrieve all tickets created in the last week by default.

## EXAMPLES

Expand All @@ -49,7 +51,8 @@ Name Title
517f2da6-9bc71cda-278fc71b-7b86-4289-baec-922e8be1a04a test 2403080040012292 Minimal Billing 3/8/2024 9:03:26 PM
test1-5dda17d0-a60d-4f4c-82e3-0fe3604c0ed4 test ticket - please ignore and close 2403060040007460 Minimal Billing 3/6/2024 3:09:28 PM
Lists all the support tickets for an Azure subscription
Lists all the support tickets for an Azure subscription.
If no parameters are specified, then this command will retrieve all tickets created in the last week by default.
### Example 2: Get a support ticket at subscription level
```powershell
Expand Down
Loading

0 comments on commit 112512e

Please sign in to comment.