Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 232869

print outputed data and send mail

$
0
0

  Hi,

 

Im kinda new to Power CLI and have found a script that list snapshots and who took em. Is there a way to get the script to mail the output to me ?

anyone who can assist

 

 

Regards

 

Christer S

 

 

$myVMs = Get-VM
$VMsWithSnaps = @()
foreach ($vm in $myVMs) {
    $vmView = $vm | Get-View
    if ($vmView.snapshot -ne $null) {
        Write-Host "VM $vm has a snapshot"
        $SnapshotEvents = Get-VIEvent -Entity $vm -type info -MaxSamples 1000 | Where {
            $_.FullFormattedMessage.contains("Create virtual machine snapshot")}
        try {
        $user = $SnapshotEvents[0].UserName
        $time = $SnapshotEvents[0].CreatedTime
        } catch [System.Exception] {
            $user = $SnapshotEvents.UserName
            $time = $SnapshotEvents.CreatedTime
        }
        $VMInfo = “” | Select "VM","CreationDate","User"
        $VMInfo."VM" = $vm.Name
        $VMInfo."CreationDate" = $time
        $VMInfo."User" = $user
        $VMsWithSnaps += $VMInfo
    }
}
$VMsWithSnaps | Sort CreationDate


Viewing all articles
Browse latest Browse all 232869

Trending Articles