OpenSourceHelpCommunity / Questions

To add your question raise an issue in this repository.
MIT License
27 stars 47 forks source link

Snapshot report with creator/owner using Powershell script #84

Open MohamedFaisal opened 2 years ago

MohamedFaisal commented 2 years ago

I have collected the codes which is collecting Snapshot Name,Descrition,Size, create Date and Creator ( owner of snapshot) However is any scheduled snapshot found in any VM and it has more than 2 then the Creator output is not coming with null user and it should show only the users related to snapshot

the reports getting auto filled in the null field of creator

Can anyone help on this?

Format html report

$htmlReport = @"

<table border=0 cellpadding=0 cellspacing=0 width=600 style='border-collapse:collapse;table-layout:fixed;width:600pt'>

Snapshots Older than 4 Days +vSphere Snapshots Daily Report: " + $snapshotCount + " snapshots" Name VM Description Size (MB) VM State Date Created User Name Name

"@

$today = Get-Date

$vmlist = Get-VM -Server $server

$snapshotCount = 0

$snapshot=get-snapshot | where {$.Created -le ($today.addDays(-4))} -WarningAction SilentlyContinue foreach ($snap in $snapshot){ $snapevent = Get-VIEvent -Entity $snap.VM -Types Info -Finish (( get-date $snap.Created).addhours(1))|Where-Object {$.UserName -notlike 'AXE\rubrikvadpr*'}|Where-Object {$.UserName -notlike 'AXE\rubrik_vadp'} | Where-Object {$_.FullFormattedMessage -imatch ‘Task: Create virtual machine snapshot’} | sort createdtime -Descending | select -First 1 if ($snapevent -ne $null){ $new1, $new2 = $snapevent.UserName.Split( "\") $us=Get-ADUser $new2|Select-Object Name

$snapshotCount = $snapshotCount + 1 $htmlReport = $htmlReport +

"" + $snap + "" + ""+ $Snap.VM + "" + ""+ $snap.Description + "" + "" + [Math]::Round($snap.SizeMB,2) + "" + "" + $Snap.VM.PowerState + "" + "" + $snap.Created + "" + "" + $snapevent.UserName + "" + "" + $us.Name + ""

} }

$htmlReport = $htmlReport + "" $htmlReport | Out-File "C:\temp\snapshot Report.html"

Disconnect-VIServer -Server $server -Force:$true -Confirm:$false

MohamedFaisal commented 2 years ago

can anyone help on this?