Hi,
I have a query that looks like this:
$cls = Get-Cluster "clusterName" | Get-VM | Get-VIEvent -Type "Info" | Where "UserName" -eq "username" | Select @{Name='Name';E={$_.vm.name}}, CreatedTime
I'm wondering how to have it only return one event per VM that is created by the user "UserName". If I run the command above it returns several events per VM.
Another question, any idea on how to clear all variables in the ISE? Sometimes i have to close and reopen the ISE to clear some variables as it hangs on to them in memory.
You could do something like this
Get-Cluster "clustername" |
Get-VM |
Get-VIEvent -Type "Info" |
Where {$_.UserName -eq $username} |
Sort-Object -Property CreatedTime -Descending |
Group-Object -Property {$_.VM.Name} |
ForEach-Object -Process {
$_.Group | Select -First 1 |
Select @{Name='Name';E={$_.vm.name}}, CreatedTime, UserName
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Variables that you create in a script should be removed after the script completes.
But not so in ISE I'm afraid.
The 'proper' way to do this is that your script cleans up at the end what it created.
And you can always do
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
