Powershell to csv

Kalaimani Thirupathi 386 Reputation points

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


I need only Backup Size detail to CSV

Azure Backup
Azure Backup
An Azure backup service that provides built-in management at scale.
779 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.
4,627 questions
{count} votes

Accepted answer
  1. AnuragSingh-MSFT 10,241 Reputation points

    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  
    "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.

    No comments

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 35,266 Reputation points

    To export just that property:

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

  2. Limitless Technology 37,351 Reputation points

    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.




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

    No comments