Hi,
Does anyone have a script that could export the settings (configuration) of a vCenter 5.0 vApp to a CSV or test file? Not a script that performs the export but just sends the settings to an output file which will allow me to create a new vApp in a different vCenter? Thank you.
Not sure which settings/properties you mean. Are they the all the vApp settings, or the vApp properties ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for your response LucD. I am looking to export the vApp settings, such as the start order, IP Allocation etc..so each setting in the tabs of your screen shot. You think that's possible?
That is possible, but not through the use of a direct PowerCLI cmdlet I'm afraid.
It will require the use of the ExtensionData property.
Exporting the info is quite easy, but the import of the settings will require the use of an API.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks. Would you be able to guide me on how to get it export it?
Hi LucD,
when you have a moment, would you happen to have any sample scripts I could use as a reference? That would help greatly! Thanks.
Sorry for the delay, does this help ?
$vAppName = 'MyVApp'
$vapp = Get-VApp -Name $vAppName
$vapp.ExtensionData.VAppConfig.Product | Select *
$vapp.ExtensionData.VAppConfig.Property | Select Label,Category,Description,UserConfigurable,DefaultValue,Value
$vapp.ExtensionData.VAppConfig.EntityConfig | Sort-object -Property StartOrder | Select Tag,StartOrder,StartDelay,WaitingForGuest,StartAction,StopAction
$vapp.ExtensionData.VAppConfig.IpAssignment | Select IpAllocationPolicy,IpProtocol
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
No problem! I will give this a shot. Also, would this go through all the vApp on my vcenter? Do I add the line to output to a file?
This will go through all the vApps
foreach($vapp in Get-VApp){
$vapp.ExtensionData.VAppConfig.Product | Select *
$vapp.ExtensionData.VAppConfig.Property | Select Label,Category,Description,UserConfigurable,DefaultValue,Value
$vapp.ExtensionData.VAppConfig.EntityConfig | Sort-object -Property StartOrder | Select Tag,StartOrder,StartDelay,WaitingForGuest,StartAction,StopAction
$vapp.ExtensionData.VAppConfig.IpAssignment | Select IpAllocationPolicy,IpProtocol
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a ton! Can I just add "export-csv" to the last line?
I'm afraid not, there is no uniform output object.
Export to a CSV works when all the objects you want write in there have the same layout.
You could create a new object into which you copy all the properties and their values, but that would require a slightly different script.
Something like this (I only some of the properties).
$report = @()
foreach($vapp in Get-VApp){
$row = New-Object PSObject
Add-Member -InputObject $row -Name Name -Value $vapp.ExtensionData.VAppConfig.Product.Name -MemberType NoteProperty
Add-Member -InputObject $row -Name Vendor -Value $vapp.ExtensionData.VAppConfig.Product.Vendor -MemberType NoteProperty
Add-Member -InputObject $row -Name Version -Value $vapp.ExtensionData.VAppConfig.Product.Version -MemberType NoteProperty
Add-Member -InputObject $row -Name ProductUrl -Value $vapp.ExtensionData.VAppConfig.Product.ProductUrl -MemberType NoteProperty
$report += $row
}
$report | Export-Csv -Path C:\report.csv -NoTypeInformation -UseCulture
But there is a problem when you reach Property, there can be more than one of these.
How would you add them to $row object ?
And when you export an array containing object with a different number of properties, the Export-Csv cmdlet only looks at the 1st element of the array, to determine how many columns there are in the CSV.
So if the element with the most properties is not at the top of the array, you will loose some properties.
The trick would be to order the rows in the array according to the number of properties.
Something like this
$report = @()
foreach($vapp in Get-VApp){
$row = New-Object PSObject
Add-Member -InputObject $row -Name Name -Value $vapp.ExtensionData.VAppConfig.Product.Name -MemberType NoteProperty
Add-Member -InputObject $row -Name Vendor -Value $vapp.ExtensionData.VAppConfig.Product.Vendor -MemberType NoteProperty
Add-Member -InputObject $row -Name Version -Value $vapp.ExtensionData.VAppConfig.Product.Version -MemberType NoteProperty
Add-Member -InputObject $row -Name ProductUrl -Value $vapp.ExtensionData.VAppConfig.Product.ProductUrl -MemberType NoteProperty
# Add more properties in a similar way
$report += $row
}
$report | Sort-Object -Property {($_ | Get-Member).Count} -Descending |
Export-Csv -Path C:\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Got it. Ok let me test the first script and go from there. I think I understand what you are saying. Thank you very muh for your assistance with this.