2

This is regarding AWS Certificate manager:

Get-ACMCertificatelist | Get-ACMCertificateDetail | Select -ExpandProperty renewalsummary | Where-object {$_.renewalStatus -ne "Success"} 

Following is the output and I want to remove those curly brackets:

DomainValidationOptions                   RenewalStatus       
-----------------------                   -------------       
{Certificate1}                         PENDING_AUTO_RENEWAL
{certificate2}                         PENDING_AUTO_RENEWAL
Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
user8172425
  • 121
  • 1
  • 7

3 Answers3

2

The object in question is actually giving you an array for the DomainValidationOptions part, which can contain more than one value.

| Select @{n="DomainValidationOptions";e={($_.DomainValidationOptions -join ",")}},RenewalStatus

putting this on the end of your query will replace the DomainValidationOptions with a comma-separated string instead of an array, but keep the name, in cases where there's only one option this technically just converts it to a string.

colsw
  • 3,216
  • 1
  • 14
  • 28
  • Following is the Output and that is not correct: DomainValidationOptions RenewalStatus ----------------------- ------------- Amazon.CertificateManager.Model.DomainValidation PENDING_AUTO_RENEWAL Amazon.CertificateManager.Model.DomainValidation PENDING_AUTO_RENEWAL – user8172425 Jun 16 '17 at 16:54
  • @user8172425 You'll need to do `$_.DomainValidationOptions.Something` then - find what `.Something` is which contains the actual string, you can get that by running `Select -Expand DomainValidationOptions` – colsw Jun 19 '17 at 08:51
1

Those are automatically added when converting a collection to a string in the formatting cmdlets. You can format the objects yourself to get rid of them.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • I am new to powerShell. Is there any sample code format them? – user8172425 Jun 16 '17 at 15:46
  • I have no clue how your objects look like (regarding properties and nesting structure), so I can't give you any example code. – Joey Jun 16 '17 at 15:49
  • Name MemberType Definition ---- ---------- ---------- DomainValidationOptions Property System.Collections.Generic.List[Amazon.CertificateManager.Model.DomainValidation] DomainValidationOptions {get;set;} – user8172425 Jun 16 '17 at 16:11
  • RenewalStatus Property Amazon.CertificateManager.RenewalStatus RenewalStatus {get;set;} – user8172425 Jun 16 '17 at 16:12
1

You can specify calculated properties for each of the properties of DomainValidationOptions that you want to drill down into.

Step 1) Discover Properties

Pipe DomainValidationOptions to Get-Member -MemberType Property to see what properties you're going to be working with:

Get-ACMCertificateList |
Get-ACMCertificateDetail |
Select -ExpandProperty RenewalSummary |
Select -ExpandProperty DomainValidationOptions |
Get-Member -MemberType Property


   TypeName: Amazon.CertificateManager.Model.DomainValidation

Name             MemberType Definition
----             ---------- ----------
DomainName       Property   string DomainName {get;set;}
ValidationDomain Property   string ValidationDomain {get;set;}
ValidationEmails Property   System.Collections.Generic.List[string] ValidationEmails {get;set;}
ValidationStatus Property   Amazon.CertificateManager.DomainStatus ValidationStatus {get;set;}

Step 2) Make Request

For the sake of example, lets say that we only want to retrieve DomainName and ValidationDomain. We would add two calculated properties for each of these properties, and then just do a regular select for RenewalStatus on the RenewalSummary object:

Get-ACMCertificateList | 
Get-ACMCertificateDetail | 
Select -ExpandProperty RenewalSummary | 
Where-object {$_.RenewalStatus -ne "Success"} |
Select @{N='DomainName';E={$_.DomainValidationOptions.DomainName}}, `
       @{N='ValidationDomain';E={$_.DomainValidationOptions.ValidationDomain}}, `
       RenewalStatus

Example Output:

DomainName                 ValidationDomain           RenewalStatus
----------                 ----------------           -------------
*.subdomain.mydomain.com   mydomain.com               PENDING_AUTO_RENEWAL
mything.mydomain.com       mydomain.com               PENDING_AUTO_RENEWAL

You can perform a similar operation for ValidationEmails, I didn't include it in this example because that would have made too many properties to format cleanly on Stack Overflow. If you wanted to unroll the collection and convert it into a string, its calculated property would look something like this:

@{N='ValidationEmails';E={$_.DomainValidationOptions.ValidationEmails -join ','}}

Further Reading

Anthony Neace
  • 25,013
  • 7
  • 114
  • 129