Powercli: Onemli Vmware eventleri Mysqle kayit etmek

Bu powercli script ile yeni acilan ve silinen sunucu adlarini bir veri tabanina kayit edebilirsiniz. loglardaki degerleri birlestirerek makine olsutran username bilgisini de kayit ediyorum.

$tableName = "vmware.events"

$VMsNewRemovedAge = 60
$records = Get-VIEventPlus -Start ((get-date).adddays(-$VMsNewRemovedAge)) -EventType @("VmCreatedEvent", "VmBeingClonedEvent", "VmBeingDeployedEvent") | Select-Object createdTime, UserName, fullFormattedMessage

$SelectQuery = "Select * FROM $tableName "
$mysqlResults = Invoke-MySQLQuery -Query $SelectQuery -ComputerName $mysqlServer -Credential $credential

foreach($record in $records){

if($mysqlResults | where CreatedTime -EQ $record.CreatedTime){

    "There is a same event"

}else{

    $CreatedTime = $record.CreatedTime
    $UserName = $record.UserName
    $FullFormattedMessage = $record.FullFormattedMessage

    $Action = $record.FullFormattedMessage.Split(" ")[0]

    if($Action -eq "Cloning"){

        $vmName = $record.FullFormattedMessage.Split(" ")[1]

    }else{

        $vmName = $record.FullFormattedMessage.Split(" ")[3]

    }




    $query = "INSERT INTO $tableName (CreatedTime,UserName,FullFormattedMessage,vmName,Action) VALUES ( '$CreatedTime','$UserName','$FullFormattedMessage','$vmName','$Action')"
    Invoke-MySQLQuery -Query $query -ComputerName $mysqlServer -Credential $credential

}

}

Disconnect-VIServer -Server * -Force -Confirm:$false

Join the ConversationLeave a reply

Your email address will not be published. Required fields are marked *

Comment*

Name*

Website