Automation

 View Only
  • 1.  Export outfile to formated table in list vm with less disk space

    Posted Mar 10, 2019 06:26 AM

    HI ,

    I need to get  the out put this report  to formatted table and send as html

    Connect-VIServer Server -user "username" -Password "password"

    ForEach ($VM in Get-VM | where-object {($_.powerstate -ne "PoweredOff") -and ($_.Extensiondata.Guest.ToolsStatus -Match ".*Ok.*")}){

    ForEach ($Drive in $VM.Extensiondata.Guest.Disk) {

    $Path = $Drive.DiskPath

    #Calculations

    $Freespace = [math]::Round($Drive.FreeSpace / 1MB)

    $Capacity = [math]::Round($Drive.Capacity/ 1MB)
    $SpaceOverview = "$Freespace" + "/" + "$capacity"

    $PercentFree = [math]::Round(($FreeSpace)/ ($Capacity) * 100)

    if ($PercentFree -lt 10) {    

        $Output = $Output + "VM: " + $VM.Name + "`n"

        $Output = $Output + "Disk: " + $Path + "`n"

        $OutPut = $Output + "Free(MB): " + $Freespace + "`n"

        $Output = $Output + "Free(%): " + $PercentFree + "`n" 

    }

    }

    }

    $Output | Out-File \path\report.csv



  • 2.  RE: Export outfile to formated table in list vm with less disk space

    Posted Mar 10, 2019 09:08 AM

    Try something like this

    Connect-VIServer Server -user "username" -Password "password"

    $Output = @()

    ForEach ($VM in Get-VM | where-object {($_.powerstate -ne "PoweredOff") -and ($_.Extensiondata.Guest.ToolsStatus -Match ".*Ok.*")}) {

       ForEach ($Drive in $VM.Extensiondata.Guest.Disk) {

       $Path = $Drive.DiskPath

       #Calculations

       $Freespace = [math]::Round($Drive.FreeSpace / 1MB)

       $Capacity = [math]::Round($Drive.Capacity / 1MB)

       $PercentFree = [math]::Round(($FreeSpace) / ($Capacity) * 100)

       if ($PercentFree -lt 10) {

       $output += "" | Select @{N = 'VM'; E = {$VM.Name}},

       @{N = 'Disk'; E = {$Path}},

       @{N = 'Free(MB)'; E = {$Freespace}},

       @{N = 'Free(%)'; E = {$PercentFree}}

       }

       }

    }

    $output | ConvertTo-Html | Set-Content -Path .\report.html


    Invoke-Item -Path .\report.html