VMware Cloud Community
jaydo123
Contributor
Contributor

powercli script to list VM's which have been migrated due to DRS

Hi am trying to get a script which will list VM's which have been VMotion due to DRS over the past day 

I have tried this but don't seem to be gatting any output even when i know that there has been vMotions happening

DRSMigationAge = 1
Get-VIEvent -maxsamples 10000 -Start (Get-Date).AddDays(-$DRSMigrateAge ) | where {$_.Gettype().Name -eq "DrsVmMigratedEvent"} | select createdTime, fullFormattedMessage | Out-GridView

any help would be appreciated

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

I think the typo in the variable name is causing that.

Try it like this

$DRSMigrateAge = 1 
Get-VIEvent
-maxsamples ([int]::MaxValue) -Start (Get-Date).AddDays(-$DRSMigrateAge ) |
where {$_ -is [VMware.Vim.DrsVmMigratedEvent]} | select createdTime, fullFormattedMessage | Out-GridView


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jaydo123
Contributor
Contributor

Thanks for getting back to me Luc 

$DRSMigrateAge = 1 
Get-VIEvent -maxsamples ([int]::MaxValue) -Start (Get-Date).AddDays(-$DRSMigrateAge ) |
 where {$_ -is [VMware.VimAutomation.DrsVmMigratedEvent]} | 
select createdTime, fullFormattedMessage | 
Out-GridView

when I save this and then run as a script it gives me the error

[VMware.VimAutomation.DrsVmMigratedEvent]: make sure that the assembly containing this type is loaded.
4\Documents\PowershellScripts\DRSMigrations.ps1:3 char:144
mples ([int]::MaxValue) -Start (Get-Date).AddDays(-$DRSMigrateAge ) | where {$_ -is [VMware.VimAutomation.DrsVmMigratedEvent] <<<< } | select createdTime, fullFormattedMessage | O
        : InvalidOperation: (VMware.VimAutomation.DrsVmMigratedEvent:String) [], RuntimeException
ErrorId : TypeNotFound
not sure what am doing wrong
please help
Reply
0 Kudos
LucD
Leadership
Leadership

That type should be [VMware.Vim.DrsVmMigratedEvent], not [VMware.VimAutomation.DrsVmMigratedEvent].


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos