alexanderp1
Contributor
Contributor

Script to query vCloud Director API for reports.

I have 2 independent scripts that query and report on specific data. Both work separately but I want to combine or merge the 2 scripts. The combined script should output the results to 1 file. Can you show me what I have to do to merge the 2 scripts?

 

Script1:


"Organization, vApp, VM, Owner, IP, OS, Description `n`r" | Out-File -FilePath c:\temp\output1.txt

$vApps = Get-CIVApp

foreach ($vApp in $vApps) {
$vApp_Name = $vApp.Name
$VMs = Get-CIVM -VApp $vApp
foreach ($VM in $VMs) {
$VM_VDC = $VM.OrgVdc
$VM_Name = $VM.name
$VAPP_Owner = $vApp.owner
$VM_OS = $VM.GuestOsFullName
$VM_desc = $VM.Extensiondata.Description

"$VM_VDC, $vApp_Name, $VM_Name, $VAPP_Owner, $VM_OS, $VM_desc `n`r" | Out-File -FilePath c:\temp\output1.txt -append
}
}

 

Script2:

 

$vapp = Get-CIVApp -name name_of_vApp
$vms = $vapp.ExtensionData.Children.vm

$vms | ForEach-Object {
[pscustomobject]@{
Name = $_.name
IpAddress = (($_.Section[2].NetworkConnection.IpAddress) -join ',')
ExternalIpAddress = ($_.Section[2].NetworkConnection.ExternalIpAddress)
}
} | Export-CSV -Path c:\temp\test.csv -NoTypeInformation

 

The results file should look like this below:

Organization, vApp, VM, Owner, IP, OS, Description

TARP1, 2008r2-mike, 2r2-mike, system, 10.0.0.150, Microsoft Windows Server 2008 R2 (64-bit), Password must be changed on first login.
MAC1, 2014 Ubuntu 12.04 Server 4.7, 2018-Ubuntu18.04LTSx64-gcc4.7, doconnor, 10.0.0.150, Ubuntu Linux (64-bit), user:root
TIC2, 2014-Windows7x64, 2014-Win7x64, system, 10.0.0.150, Microsoft Windows 7 (64-bit), User: ielect
PITS, Ubuntu18GoldImage, 2018Ubuntu18GoldImage, system, 10.0.0.150, Ubuntu Linux (64-bit), Password expires on 12/31/2020
HIP-OPEN, 2018w10, 2018w10fr5, system, 10.0.0.150, Microsoft Windows 8 (64-bit), User: admin1

...

 

 

0 Kudos
0 Replies