VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Unable to capture VM Information

Hi,

I am unable to capture the passed and failed VM details in the output file. I am not getting any error but data is not getting captured

Please help.

$report = @()

$reportNotFound = @()

Import-Csv -Path $reportlocation1 -UseCulture -PipelineVariable row |

ForEach-Object -Process {

    $sInvoke = @{

        VM              = $_.Name

        GuestCredential = $Creds

        ScriptTYpe      = 'powershell'

        ScriptText      = $ScriptBlock

        ErrorAction = 'Stop'

    }

    try{

        Invoke-VMScript @sInvoke

        "$($row.Name) DNS has been changed"

        $report = $($row.Name)

       }

    catch{

        Throw "DNS Failed for $($row.Name)"

        $reportNotFound = $($row.Name)

    }

    $result

}

$report | Export-Excel -Path ".\DNS_Info.xlsx" -AutoFilter -AutoSize -BoldTopRow -FreezeTopRow -WorksheetName VM_Info

$reportNotFound | Export-Excel -Path ".\DNS_Info.xlsx" -AutoFilter -AutoSize -BoldTopRow -FreezeTopRow -WorksheetName VMs_Not_Found_Info

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Those lines should be

$report += $($row.Name)

and

$reportNotFound += $($row.Name)


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Those lines should be

$report += $($row.Name)

and

$reportNotFound += $($row.Name)


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

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That worked. Thank you very much Smiley Happy

0 Kudos