question

KalaimaniThirupathi-5306 avatar image
0 Votes"
KalaimaniThirupathi-5306 asked LimitlessTechnology-2700 answered

Powershell to csv

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


windows-server-powershellazure-backup
image.png (15.7 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@KalaimaniThirupathi-5306, I wanted to check if you had a chance to review the answers provided below. Please let us know if you have any queries or concerns.
Please 'Accept as answer' if it helped so that it can help others in the community looking for help on similar topics.

0 Votes 0 ·
AnuragSingh-MSFT avatar image
0 Votes"
AnuragSingh-MSFT answered

Hi @KalaimaniThirupathi-5306

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

To export just that property:

 $detail |
     Select-Object "Backup Size" |
         Export-Csv c:\junk\BackupSize.csv -NoTypeInformation
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered

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://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/convertto-csv?view=powershell-7.1

https://docs.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--

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.