VMware Cloud Community
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
LucD
Leadership
Leadership

There are several snapshot reports available, but a good start would be Alan's SnapReminder


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

chrislcrain
Contributor
Contributor

Hi bansne,

Get-snapshot is your best bet. Connect to the vCenters you are trying to collect on and run this one liner. Not that efficient, but pretty simple. It will export a csv report to your C drive with the details you requested. SizeGB for me was formatted to like a million decimal places- easily fixable, but not really worth complicating things.

get-vm | get-snapshot | select vm, sizegb, created, description, name | Export-Csv C:\Snapshots.csv -Append -NoType

There are better, less readable ways to do it if you're solely concerned about speed. Let me know how you make out.

bansne
Enthusiast
Enthusiast

Thanks LucD and chrislcrain ,

I will check both and post you with update Smiley Happy

Reply
0 Kudos
vmk2014
Expert
Expert

LucD,

   When i tried to execute the snapshot reminder script (by Alan), it throws error.

Exception calling "Add" with "1" argument(s): "Value cannot be null.

Parameter name: item"

At C:\tmp\Snapshot-Reminder.ps1:86 char:4

+    $msg.To.Add($Mailto)

+    ~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : ArgumentNullException

Exception calling "Send" with "1" argument(s): "A recipient must be specified."

At C:\tmp\Snapshot-Reminder.ps1:99 char:4

+    $smtp.Send($msg)

+    ~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : InvalidOperationException

Exception calling "Add" with "1" argument(s): "Value cannot be null.

Parameter name: item"

At C:\tmp\Snapshot-Reminder.ps1:86 char:4

+    $msg.To.Add($Mailto)

+    ~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : ArgumentNullException

Exception calling "Send" with "1" argument(s): "A recipient must be specified."

At C:\tmp\Snapshot-Reminder.ps1:99 char:4

+    $smtp.Send($msg)

+    ~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : InvalidOperationException

Any idea where the correction is required ?

Thanks

VM2014

Reply
0 Kudos
vbrad6841
Enthusiast
Enthusiast

vmk2014,

     Although Alan's scripts can sometimes seem like AI it appears that some of the necessary info is missing that the script needs to gather to run successfully.  It appears that the user that created the snap in vCenter either 1) doesn't have a valid email address associated to their AD account or 2) the script didn't have the correct AD permissions to search for the user.

- Validate the user has an email in AD

- Validate the username in vCenter and the username in AD are the same

- Validate the account running the script has the correct permissions in AD

     If you're looking for something a bit simpler you could proceed as chrislcrain recommended and create a foreach loop for all your VC's to collect all the data in 1 spreadsheet

$vcenters = "vc1", "vc2"

foreach ($vcenter in $vcenters){

     connect-viserver $vcenter

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

     disconnect-viserver $vcenter

     }

Hope this helps!

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

Hi Vbrad,

      Thanks for your response.It will be helpful, but I have multiple VC's in different domain (region/global) and different id ?. How to extract the snapshot.

Thanks

vm2014

Reply
0 Kudos
vmk2014
Expert
Expert

Hi Vbrad6841,

          One more thing, i noticed while running the script, it prompts to disconnect from VC, since we have multiple VC's and its require manual interference to answer (Y/N).

thanks

vm2014

Reply
0 Kudos
vbrad6841
Enthusiast
Enthusiast

Sorry, corrected the disconnect prompt...

Added logic to collect credentials.  To provide the correct creds for the correct host you'll need to determine a variable on the host which provides the domain name.  I currently use FQDN as we add our hosts to vcenter with FQDN.

$vcenters = "vc1", "vc2"

$cred1 = get-credential

$cred2 = get-credential

foreach ($vcenter in $vcenters){

     connect-viserver $vcenter -credential $cred1

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

     disconnect-viserver $vcenter -confirm:$false

     }

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

vbrad6841,

        Can we schedule the script to pull the report through Schedule tasks job ? Also, Cred$1(domain 1),Cred2$ (Domain 2)will prompt for password ?

thanks

vm2014

Reply
0 Kudos
vmk2014
Expert
Expert

Hi vbrad6841,

          When i execute the script it pulls the snapshot for backup also (Backup done by Avamar tools) but i want to pull only the manual snapshot.

thanks

vm2014

Reply
0 Kudos
vbrad6841
Enthusiast
Enthusiast

Yes, you should be able to schedule as a task.  You'll need to ensure you have credentials (service account) to run the script that has access to the various domains you're going to hitting.

As for the backup snapshot exclusion you could use a "where" clause to exclude the Avamar backup jobs.  You'll have to identify some type of descriptor on the Avamar snapshots to exclude them.  Something like this...

get-vm | get-snapshot | ?{$_.description -notmatch "Description of your Avamar snap"} | select vm, sizegb, created, description, name | Export-CSV c:\temp\Snapshot.csv -append -notype

Blog: https://lowercasevblog.wordpress.com/
bansne
Enthusiast
Enthusiast

Alan Script talks about using snmp addess , here i need to have different VCs , all VCs include different snmp address.  Not sure if it is possible to have multiple address mentioned in one script

Reply
0 Kudos
LucD
Leadership
Leadership

Do you mean SMTP or SNMP ?

Is it for sending emails ?


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

Reply
0 Kudos
bansne
Enthusiast
Enthusiast

Smtp for sending emails

Reply
0 Kudos
LucD
Leadership
Leadership

Alan's script sends a reminder via email to the creator of the snapshot.

What exactly do you want to do ?

Send the reminder to multiple people ?


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

Reply
0 Kudos
bansne
Enthusiast
Enthusiast

all i need to have email send to me only

Reply
0 Kudos
LucD
Leadership
Leadership

Try replacing this line

$mailto = ((Find-User $SnapshotInfo.Creator).Properties.mail)

by this (fill in your real email address of course)


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

Reply
0 Kudos
vmk2014
Expert
Expert

Thanks LucD for your help. When i tried to replace, i got the following error

$mailto = ((Find-User $SnapshotInfo.Creator).Properties.mail)

by this (fill in your real email address of course)

$mailto = "your.address@domain.com"

Error :-

PowerCLI C:\tmp> .\Snapshot-Reminder.ps1

Name                           Port  User

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

ANZpgicwsrv001.us.xyz.com   443   AN\Admin

Exception calling "Send" with "1" argument(s): "The SMTP server requires a

secure connection or the client was not authenticated. The server response

was: 5.7.1 Client was not authenticated"

At C:\tmp\Snapshot-Reminder.ps1:99 char:4

+    $smtp.Send($msg)

+    ~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : SmtpException

Thanks

vm2014

Reply
0 Kudos
bansne
Enthusiast
Enthusiast

Exception calling "Send" with "1" argument(s): "The SMTP server requires a

secure connection or the client was not authenticated. The server response

was: 5.7.1 Client was not authenticated"

There seems to be authentication issue for you. Do a test email try and see if it works then try via script