Hi All,
I'm trying to fetch the VM's removed in last 24 hours, but when i execute the script, it fails with an errors. Any pointers will be much appreciated.
$fragments += $start = (Get-Date).AddDays(-1) | Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) | where{$_ -is [VMware.Vim.VmRemovedEvent]}
Sort-Object -Property CreatedTime, UserName |
ConvertTo-Html -Fragment -PreContent "<H2>VM's deleted in last 24 hours</H2>"
Thanks
V
Not sure where you got that code from, but you can'f feed the Start parameter over the pipeline to Get-VIEvent.
Also not sure why you use a Fragment in this script.
Try something like this
Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) | where{$_ -is [VMware.Vim.VmRemovedEvent]} |
Sort-Object -Property CreatedTime, UserName |
ConvertTo-Html -PreContent "<H2>VM's deleted in last 24 hours</H2>" | Out-String |
Out-File -FilePath .\report.html
Invoke-Item -Path .\report.html
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Not sure where you got that code from, but you can'f feed the Start parameter over the pipeline to Get-VIEvent.
Also not sure why you use a Fragment in this script.
Try something like this
Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) | where{$_ -is [VMware.Vim.VmRemovedEvent]} |
Sort-Object -Property CreatedTime, UserName |
ConvertTo-Html -PreContent "<H2>VM's deleted in last 24 hours</H2>" | Out-String |
Out-File -FilePath .\report.html
Invoke-Item -Path .\report.html
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you, LucD. As you recommended that most of this is available in another thread, hence i took the code from your thread for multiple tasks but doesn't send report but its failing.
with an error. It will run forever as shown in screenshot. I'm getting report for another tasks but it taking time due to this VM removed event.
I used the code recommended by you.and removed the pipline and i have used the thread from PowerCLI Script Required for Multiple Tasks
and Report VMs deleted past 90 days
$fragments += $start = (Get-Date).AddDays(-1)
Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) | where{$_ -is [VMware.Vim.VmRemovedEvent]}
Sort-Object -Property CreatedTime, UserName |
ConvertTo-Html -Fragment -PreContent "<H2>VM's deleted in last 24 hours</H2>"
Thanks
V
The code is working for me.
Which error are you getting?
"run forever"? Are you sure, the Get-VIEvent might run a rather long time.
Perhaps change the $start to (Get-Date).AddHours(-1) as a test.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes, LucD. It works for me as well, but it takes time and it doesn't come in mail box. I'm able to receive for DRS,VMotion and host maintenance mode report without any issue.
"run forever"? No. Are you sure, the Get-VIEvent might run a rather long time. - yes. Ideally the below output should not onscreen instead of sending over mail.
Thanks
V
That is because you didn't copy the pipeline symbol at the end of Get-VIEvent line
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LuCD,
I'm using the below code. It will take time show output on the console and no report over mail. I have used the pipeline at the end of Get-VIEvent line
$fragments += $start = (Get-Date).AddDays(-1)
Get-VIEvent -Start $start -MaxSamples ([int]::MaxValue) | where{$_ -is [VMware.Vim.VmRemovedEvent]}
Sort-Object -Property CreatedTime, UserName |
ConvertTo-Html -Fragment -PreContent "<H2>VM's deleted in last 24 hours</H2>"
# Send email
$sMail = @{
From = 'abc@domain.com'
To = 'subcon@domain.com'
Subject = 'VM report'
SmtpServer = 'smtp.ab.xyz.com'
BodyAsHtml = $true
Body = ConvertTo-Html -Head $style -Body $fragments | Out-String
}
Send-MailMessage @sMail
}
Disconnect-VIServer -Server $vcenters -Confirm:$false
Really?
I have now posted a working script and shown you where the issue with your code is, but you apparently won't listen or correct your code.
Sorry, I have better things to do then keep repeating myself to someone who will not read or listen.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
No error. I got it.
Thanks