bansne
Enthusiast
Enthusiast

PoweCli Script to Export Snaphost Details of Multiple VCs

Hi,

I could get the details from RV tools per VC , but i want to get details of snapshot details of multiple VCs in sheet.

All i need is single sheet with 1) different VCs snapshot details with a) total snapshost size in GB , b) date when it was created , c) who created/if not then description. , d) VM Name

Thanks in advance !

Best Regards,

Neha Bansal

44 Replies
vbrad6841
Enthusiast
Enthusiast

So I think this might be your issue, correct me if I'm wrong....

$vcenters = "VC1"

$cred1 = get-credential

  foreach ($vcenter in $vcenters){

     connect-viserver $vcenter -credential $cred1

     get-vm | get-snapshot | select vm, sizegb, created, description, name | Export-CSV D:\Script\test\Snapshot.csv -append -notype

     disconnect-viserver $vcenter -confirm:$false

     }

$mailto = 'mail.com'

$mailfrom = 'sendermail'

$mailsubject = 'Snapshot_Report'

$smtpserver = 'smtp server'

$mailbody = "Snapshot Reminder"

$attach1 = "D:\Script\test\Snapshot.csv"

Send-MailMessage -To $mailto -From $mailfrom -Subject $mailsubject -SmtpServer $smtpserver -Body $mailbody -Attachments $attach1

Remove the sections that are strikethrough.  Make sure that in the settings of your scheduled task you set the task to run with a user that has the necessary rights in vCenter and ensure the scheduled task is configured in the attached image.  .  This will force the script to run in the context of the user running the scheduled tasks.

Capture.JPG.

Blog: https://lowercasevblog.wordpress.com/
0 Kudos
vmk2014
Expert
Expert

Thanks !! it worked this time with output generated.

Now i have to pull multiple VC like VC1 - Domain1, VC2 - Domain2 , VC3 - Domain3 and VC4 - Domain 4. All with different credential

Thanks once again !!

vm2014

0 Kudos
vmk2014
Expert
Expert

Hi Vbrad6841,

          How to send emails to multiple recipient ? e.g. $mailto = 'mailto@email.com'mailto@email.com'mailto@email.com','mailto@email.com'mailto@email.com' ?

thanks

vm2014

0 Kudos
vbrad6841
Enthusiast
Enthusiast

Like this...

-to "User02 <user02@example.com>", "User03 <user03@example.com>"

Blog: https://lowercasevblog.wordpress.com/
0 Kudos
ms5812
Enthusiast
Enthusiast

vmk2014

Did you ever get this one sorted out? I'm needing to do the same thing and could use some help.

Thanks

Mark

0 Kudos