Automation

 View Only
  • 1.  Get date when Datastore was created past 12 hours

    Posted Jun 13, 2024 07:04 AM

    Hi,

    Is there a way to get the creation date of datastores within the past 12 hours?

    regards

    Andi



  • 2.  RE: Get date when Datastore was created past 12 hours

    Posted Jun 13, 2024 07:22 AM
    Edited by LucD Jun 13, 2024 07:32 AM

    You could try something like this

    Get-VIEvent -Start (Get-Date).AddHours(-12) -MaxSamples ([int]::MaxValue) |
    Where-Object { $_ -is [VMware.Vim.VMFSDatastoreCreatedEvent] -or
      $_ -is [VMware.Vim.NASDatastoreCreatedEvent] -or
      $_ -is [VMware.Vim.LocalDatastoreCreatedEvent] } |
    Select-Object CreatedTime, UserName, 
      @{N = "Name"; E = { $_.Datastore.Name }},
      @{N = "Type"; E={$_.GetType().Name.Replace('DatastoreCreatedEvent','')}}



    ------------------------------


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


    ------------------------------



  • 3.  RE: Get date when Datastore was created past 12 hours

    Posted Jun 13, 2024 08:14 AM

    Hi Luc,

    Works fine.

    Thank you.

    Greetings

    Andi




  • 4.  RE: Get date when Datastore was created past 12 hours

    Posted Jun 13, 2024 09:12 AM

    Hi Luc,

    I want to export the output as mail, but there ist no Data in the Body.

    Datastore Report vCenter

    06/13/2024 14:54:19

    Script:

    # HTML header style
    $Header = @"
    <style>
    TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}
    TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;}
    TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
    </style>
    "@

    $From = "Datastore-Created-Report@ich.at"
    $Subject = "Datastore Created Report - $((Get-Date).ToShortDateString())"
    $SMTPserver = "smtp.ich.at"
    $To = "ich@ich.at"

     
    $Report = Get-VIEvent -Start (Get-Date).AddHours(-24) -MaxSamples ([int]::MaxValue) | where{$_ -is 'VMware.Vim.VMFSDatastoreCreatedEvent' -or $_ -is 'VMware.Vim.NASDatastoreCreatedEvent' -or $_ -is 'VMware.Vim.LocalDatastoreCreatedEvent'} | Select CreatedTime, @{N="Name";E={$_.Datastore.Name}} 


    $Report = $Report | 
        ConvertTo-Html -Head $Header -title "Datastore Created Report" -body "<H1>Datastore Report vCenter</H1>"  -pre (get-date)

    $MailSplat = @{
        To         = $To
        From       = $From
        Subject    = $Subject
        Body       = ($Report | Out-String)
        BodyAsHTML = $true
        SMTPServer = $SMTPServer
    }

    Send-MailMessage @MailSplat

    exit

    greetings

    Andi




  • 5.  RE: Get date when Datastore was created past 12 hours

    Posted Jun 13, 2024 01:14 PM

    Seems to work for me.
    Is there anything in $Report?



    ------------------------------


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


    ------------------------------



  • 6.  RE: Get date when Datastore was created past 12 hours

    Posted Jun 14, 2024 07:58 AM

    Hi Luc,

    It works. I've taken the wrong time slot for new creatd DS.

    Thank you.

    Greetings

    Andi