-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-vCenterOrgs.ps1
80 lines (60 loc) · 2.1 KB
/
get-vCenterOrgs.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
Add-PSSnapin VMware.VimAutomation.Core
Add-PSSnapin vmware.vimautomation.cloud
#this is a changes
$VCUsername = "astepga"
$VCPassword = "Bluealert1981_"
$VCoutputfile = "D:\Software\Scripts\temp_vcenter_orgs.csv"
$location = "LO1"
$basefolder = $location + "pvcd"
$VCFQDN=$location + "wpvcdvcs002.dcsprod.dcsroot.local"
Function getvCenterOrgs{
Connect-VIServer -Server $VCFQDN -User $VCUsername -Password $VCPassword
$orgArray = Get-Folder -Location $basefolder -Type VM -NoRecursion | Select -ExpandProperty Name
Out-File -FilePath $VCoutputfile -inputobject "Org,OrgvDC,vApp,VM" -encoding ASCII
ForEach ($org in $orgArray)
{
$orgName = $org.split()
#Write-Host "Currently Selected vOrg is: " $orgName[0]
$vdcArray = Get-Folder -Location $org -NoRecursion -Type VM | Select -ExpandProperty Name
ForEach ($vdc in $vdcArray)
{
$vdcName = $vdc.Split()
#Write-Host "Listing vApps for vDC " $vdcName[0]
$vAppArray = Get-Folder -Location $vdc -NoRecursion -Type VM | Select -ExpandProperty Name
ForEach ($vApp in $vAppArray)
{
$vAppName = $vApp.Split()
#Write-Host "Listing VMs under vApp: " $vAppName[0]
$vmArray = Get-VM -Location $vApp | Select -ExpandProperty Name
ForEach ($vm in $vmArray)
{
$vmName = $vm.Split()
$csvstring = $orgName[0] + "," + $vdcName[0] + "," + $vAppName[0] + "," + $vmName[0]
Write-Host "Writing: " $csvstring
Out-File -FilePath $VCoutputfile -Append -inputobject $csvstring -encoding ASCII
Clear-Variable vmName
}
}
}
}
Clear-Variable org
Clear-Variable orgArray
Clear-Variable orgName
Clear-Variable vdc
Clear-Variable vdcArray
#Clear-Variable vcdName
Clear-Variable vApp
Clear-Variable vAppArray
Clear-Variable vAppName
Clear-Variable vm
Clear-Variable vmArray
Clear-Variable vmName
Clear-Variable csvstring
#Disconnect from vCenter
write-host "Disconnecting vCenter..."
disconnect-viserver -server * -Confirm:$false -force
}
Function getvCDOrgs{
}
#getvCenterOrgs
getvCDOrgs