I have a report that inputs values from a csv. The csv has 4 columns: vmname, dateCreated, User, vmhost
Using this CSV, I run the following report to see if the VMs are in vCenter, and I save the vms that still exist to a new outputfile:
$array = @()
Import-Csv c:\inputfile.csv -UseCulture | %{
Try {
Get-VM -Name $_.VMName -ErrorAction Stop | Out-Null
}
Catch {return
}
$array += $_
}
$array | Export-Csv c:\outputfile.csv -NoTypeInformation -UseCulture
Can I modify this report to add to each array element the amount of RAM that the VM currently has and output that as an additional column to my outputfile?
You can use the Add-Member for that.
Something like this for example
$array = @()
Import-Csv c:\inputfile.csv -UseCulture | %{
Try {
Get-VM -Name $_.VMName -ErrorAction Stop | Out-Null
}
Catch {return
}
$array += ($_ | Add-Member -Name NewColumn -Value 123 -MemberType NoteProperty -Passthru)
}
$array | Export-Csv c:\outputfile.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use the Add-Member for that.
Something like this for example
$array = @()
Import-Csv c:\inputfile.csv -UseCulture | %{
Try {
Get-VM -Name $_.VMName -ErrorAction Stop | Out-Null
}
Catch {return
}
$array += ($_ | Add-Member -Name NewColumn -Value 123 -MemberType NoteProperty -Passthru)
}
$array | Export-Csv c:\outputfile.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That works thanks again