-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path1085.ps1
More file actions
50 lines (48 loc) · 1.53 KB
/
Copy path1085.ps1
File metadata and controls
50 lines (48 loc) · 1.53 KB
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
#requires -pssnapin VMware.Vimautomation.Core
Param(
[int]
$LastDays
)
Process
{
$EventFilterSpecByTime = New-Object VMware.Vim.EventFilterSpecByTime
If ($LastDays)
{
$EventFilterSpecByTime.BeginTime = (get-date).AddDays(-$($LastDays))
}
$EventFilterSpec = New-Object VMware.Vim.EventFilterSpec
$EventFilterSpec.Time = $EventFilterSpecByTime
$EventFilterSpec.DisableFullMessage = $False
$EventFilterSpec.Type = "VmCreatedEvent","VmDeployedEvent","VmClonedEvent","VmDiscoveredEvent","VmRegisteredEvent"
$EventManager = Get-View EventManager
$NewVmTasks = $EventManager.QueryEvents($EventFilterSpec)
Foreach ($Task in $NewVmTasks)
{
# If VM was deployed from a template then record which template.
If ($Task.Template -and ($Task.SrcTemplate.Vm))
{
$srcTemplate = Get-View $Task.SrcTemplate.Vm -Property name |
Select -ExpandProperty Name
}
Else
{
$srcTemplate = $null
}
write-output ""|Select-Object @{
Name="Name"
Expression={$Task.Vm.name}
}, @{
Name="Created"
Expression={$Task.CreatedTime}
}, @{
Name="UserName"
Expression={$Task.UserName}
}, @{
Name="Type"
Expression={$Task.gettype().name}
}, @{
Name="Template"
Expression={$srcTemplate}
}
}
}