2 Replies Latest reply on May 17, 2018 3:16 PM by TangKing2moya

    HOW Make "VM GUEST DISK SIZES Script " export CSV file

    TangKing2moya Lurker

       

      hello everyone

       

      I want to export the following script as a CSV file.

       

      Original :

      ForEach ($VM in ( Get-VM |Get-View)){($info = $VM.Guest.Disk |Select @{N=“Name“;E={$VM.Name}},DiskPath, @{N=“Capacity(GB)“;E={[math]::Round($_.Capacity/ 1GB)}}, @{N=“Free Space(GB)“;E={[math]::Round($_.FreeSpace / 1GB)}}, @{N=“Free Space %“;E={[math]::Round(((100 * ($_.FreeSpace))/ ($_.Capacity)),0)}})|Format-Table}

       

      Export CSV:

      ForEach ($VM in ( Get-VM |Get-View)){($info = $VM.Guest.Disk |Select @{N=“Name“;E={$VM.Name}},DiskPath, @{N=“Capacity(GB)“;E={[math]::Round($_.Capacity/ 1GB)}}, @{N=“Free Space(GB)“;E={[math]::Round($_.FreeSpace / 1GB)}}, @{N=“Free Space %“;E={[math]::Round(((100 * ($_.FreeSpace))/ ($_.Capacity)),0)}})| Export-Csv -path  c:\test.csv -NoTypeInformation |Format-Table  }

       

      It will be saved only once, not all information.

       

      What is the problem?

       

      Thanks!