VMware Cloud Community
lanz80
Contributor
Contributor

Avoid the return carriage, when storing the Object property in a .csv file

Hi,When retrieving the "Description" Object of Get-Snapshot, to store the value in the .csv file, it makes a carriage return, jumping to the next line but I want it to store the information without jumping the line.

This is the snnipet:   

 

I supposse that I have to change here  ( marked in bold), but I dont know why:

  $Report = Get-Snapshot -VM $Vm | Select-Object VM, Description, @{Label = "Size"; Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created, IsCurrent | Where-Object { $_.Created -lt (Get-Date).AddDays(-30) }

 

 

$Report = Get-Snapshot -VM $Vm | Select-Object VM, Description, @{Label = "Size"; Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created, IsCurrent | Where-Object { $_.Created -lt (Get-Date).AddDays(-30) }

                
                if (-not $Report) {
                    $Report = New-Object PSObject -Property @{
                        VM          = "No snapshots found on $($Vm)"
                        Description = ""
                        Size        = ""
                        Created     = ""
                        IsCurrent   = ""
                    }

                 }

                 $Report | Format-List VM, Description, Size, Created, IsCurrent
                 $Report = ($Report | Select-Object -Property VM, Description, Size, Created, IsCurrent | ForEach-Object { "$($_.VM)" + ',' + "$($_.Description)" + ',' + "$($_.Size)" + ',' + "$($_.Created)" + ',' + "$($_.IsCurrent)"})
                 Add-Content -Path $file -Value $Report

 

 

 

I would appreciate any help to solve this issue.  Thanks in advance!

 

King regards

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

You can replace the NL (newline) with a space.

$Report = Get-Snapshot -VM $Vm | 
  Select-Object VM, 
  @{N='Description';E={$_.Description.Replace("`n",' ')}}, 
  @{Label = "Size"; Expression={"{0:N2} GB" -f ($_.SizeGB)}},Created, IsCurrent | Where-Object { $_.Created -lt (Get-Date).AddDays(-30) }


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
lanz80
Contributor
Contributor

Thank you master!   Works perfect!

 

Kind regards

Reply
0 Kudos