-
Notifications
You must be signed in to change notification settings - Fork 1
/
CloudStackReportVirtualMachines.ps1
147 lines (142 loc) · 7.75 KB
/
CloudStackReportVirtualMachines.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<#
.SYNOPSIS
A CloudStack/CloudPlatform Virtual Machine Listing Scriptlet.
.DESCRIPTION
List all virtual machines running within a CloudStack Cloud.
.PARAMETER zoneid
The zone ID to list VMs from.
.EXAMPLE
CloudStackListVirtualMachines.ps1 -zoneid e697daf1-a747-4152-a5ac-992bad096653
#>
# Writen by Jeff Moody ([email protected])
#
# 2013/5/17 v1.0 created
Param(
[String]
$zoneid
)
Import-Module CloudStackReportsClient
$parameters = Import-CloudstackReportsConfig
$EMails = $parameters[3]
$mailbody = ""
$hostname = $env:COMPUTERNAME
if ($parameters -ne 1) {
$cloud = New-CloudStackReports -apiEndpoint $parameters[0] -apiPublicKey $parameters[1] -apiSecretKey $parameters[2]
if ($zoneid) {
$job = Get-CloudStackReports -cloudStack $cloud -command listVirtualMachines -options zoneid=$zoneid
}
else {
$job = Get-CloudStackReports -cloudStack $cloud -command listVirtualMachines
}
$allVMs = $job.listvirtualmachinesresponse
foreach ($VM in $allVMs.virtualmachine) {
$VMID = $VM.id
$VMNAME = $VM.name
$VMDISPLAYNAME = $VM.displayname
$VMZONENAME = $VM.zonename
$VMTEMPLATE = $VM.templatedisplaytext
$mailbody += "Virtual Machine $VMDISPLAYNAME (ID: $VMID) is running '$VMTEMPLATE' in $VMZONENAME<br />`n"
}
Write-Debug "Mail body: `n$mailbody"
Send-MailMessage -From "cloud@$hostname" -To $EMails -Body $mailbody -Subject "CloudStack Instance List" -BodyAsHtml -SmtpServer localhost
}
else {
Write-Error "Please configure the $env:userprofile\cloud-settings.txt file"
}
# SIG # Begin signature block
# MIIRpQYJKoZIhvcNAQcCoIIRljCCEZICAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU1bgSYGgEieCaki4L4jQ3GckQ
# XeCggg3aMIIGcDCCBFigAwIBAgIBJDANBgkqhkiG9w0BAQUFADB9MQswCQYDVQQG
# EwJJTDEWMBQGA1UEChMNU3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERp
# Z2l0YWwgQ2VydGlmaWNhdGUgU2lnbmluZzEpMCcGA1UEAxMgU3RhcnRDb20gQ2Vy
# dGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMDcxMDI0MjIwMTQ2WhcNMTcxMDI0MjIw
# MTQ2WjCBjDELMAkGA1UEBhMCSUwxFjAUBgNVBAoTDVN0YXJ0Q29tIEx0ZC4xKzAp
# BgNVBAsTIlNlY3VyZSBEaWdpdGFsIENlcnRpZmljYXRlIFNpZ25pbmcxODA2BgNV
# BAMTL1N0YXJ0Q29tIENsYXNzIDIgUHJpbWFyeSBJbnRlcm1lZGlhdGUgT2JqZWN0
# IENBMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyiOLIjUemqAbPJ1J
# 0D8MlzgWKbr4fYlbRVjvhHDtfhFN6RQxq0PjTQxRgWzwFQNKJCdU5ftKoM5N4YSj
# Id6ZNavcSa6/McVnhDAQm+8H3HWoD030NVOxbjgD/Ih3HaV3/z9159nnvyxQEckR
# ZfpJB2Kfk6aHqW3JnSvRe+XVZSufDVCe/v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