Powershell to csv

Kalaimani Thirupathi 411 Reputation points
2021-11-05T04:00:14.813+00:00

Hi All,

Powershell property data need to export to Powershell. Kindly help with this.

PS C:\> $detail.Properties

Key Value


VM Name gz-zweappxxxxx
Backup Size 1446 MB

146696-image.png

I need only Backup Size detail to CSV

Azure Backup
Azure Backup
An Azure backup service that provides built-in management at scale.
1,126 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,364 questions
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 19,856 Reputation points
    2021-11-05T08:14:29.583+00:00

    Hi @Kalaimani Thirupathi

    Welcome to Microsoft Q&A! Thanks for posting the question.

    Based on my understanding, you want to export only the second line to csv (please correct me if I misunderstood it). There are multiple ways to achieve it based on your requirement. The following samples should help:

    1. If you want to capture only the second line (based on the screenshot shared), you may use the following:

    #test object  
    PS D:\Data\tmp> $test_obj  
      
    Key         Value     
    ---         -----     
    VM Name     Test VM1  
    Backup Size 1500 MB   
      
    #convert the "Backup Size" to csv, ignoring first entry  
    PS D:\Data\tmp> $test_obj.GetEnumerator() | select -skip 1 | ConvertTo-Csv -NoTypeInformation  
    "Key","Value"  
    "Backup Size","1500 MB"  
    

    2. If you do not want to get the header ("Key", "Value") in output:

    PS D:\Data\tmp> $test_obj.GetEnumerator() | select -skip 1 | ConvertTo-Csv -NoTypeInformation | select -skip 1  
    "Backup Size","1500 MB"  
    

    3. If you only require the exact value of backup size, you may use the following:

    PS D:\Data\tmp> $test_obj.GetEnumerator() | select -skip 1 -ExpandProperty Value  
    1500 MB  
    		  
    #Or you may also use the following  
    PS D:\Data\tmp> $test_obj["Backup Size"]  
    1500 MB  
    

    Please let me know if you have any questions.

    ---
    Please 'Accept as answer' and ‘Upvote’ if it helped so that it can help others in the community looking for help on similar topics.

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 44,776 Reputation points
    2021-11-05T21:42:51.887+00:00

    To export just that property:

    $detail |
        Select-Object "Backup Size" |
            Export-Csv c:\junk\BackupSize.csv -NoTypeInformation
    
    0 comments No comments

  2. Limitless Technology 39,351 Reputation points
    2021-11-10T10:46:22.013+00:00

    Hi there,

    The Export-CSV cmdlet creates a CSV file of the objects that you submit. Each object is a row that includes a comma-separated list of the object's property values. You can use the Export-CSV cmdlet to create spreadsheets and share data with programs that accept CSV files as input.

    You can refer these two links and get the required cmdlets for fetching the data out as csv.

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-csv?view=powershell-7.1

    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/export-csv?view=powershell-7.1

    -------------------------------------------------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments