Below is my script. It is not working and need some help. It is going on every VM and placing the user who created the snapshot in the description but I can not figure out how to make it only do each VM once. I want to run this weekly so I can find the people who did not follow our snapshot policy. some snapshots I keep for a bit and do not want the user to be put it on description. It is putting domain/user and I am trying to look at the description and see if the domain/ is there.
Add-pssnapin VMware.VimAutomation.Core
$viserver = "viserver"
$secpasswd = ConvertTo-SecureString "password" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("user", $secpasswd)
Connect-VIServer $viserver -Credential $mycreds
foreach ($snap in Get-VM | Get-Snapshot)
{$snapevent = Get-VIEvent -Entity $snap.VM -Types Info -Finish $snap.Created -MaxSamples 1 | Where-Object {$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'}
if ($snapevent -ne $null){
$description = ConvertTo-Csv $snap.Description
if ($description -notcontains "domain"){
$username = $snapevent.UserName
$description = $snap.Description
Write-Host $description
Set-Snapshot $snap -Description "$username $description"
Write-Host ( "VM: "+ $snap.VM + ". Snapshot '" + $snap + "' created on " + $snap.Created.DateTime + " by " + $snapevent.UserName +".")}
else {
Continue
}
}}
#