HPE Nimble Storage Solution Specialists
1753659 Members
5847 Online
108798 Solutions
New Discussion

Re: Script to find NSs Snapshots

 
RyanE
Regular Visitor

Script to find NSs Snapshots

Hey Everyone,  I thought I'd share my script to automate the discovery and email the System Snapshots created by expanding a volume. 

Create a service account, log into the machien were you want the password to reside and run the script from.  Then create the encrypted password with this command:

Read-Host "PASSHERE" -AsSecureString | ConvertFrom-SecureString | Out-File "C:\location\to\pass.txt"

The password file can only be unencrypted with the service account, so make the scheduled task to run as that user.

#loads encrypted password
$securePass = Get-Content C:\location\to\pass.txt

#Decrypts password
$pass = $securePass | ConvertTo-SecureString
$Ptr = [System.Runtime.InteropServices.Marshal]::SecureStringToCoTaskMemUnicode($pass)
$decrypted = [System.Runtime.InteropServices.Marshal]::PtrToStringUni($Ptr)
[System.Runtime.InteropServices.Marshal]::ZeroFreeCoTaskMemUnicode($Ptr)

#Email parrameterss.
$EmailFrom = “emailfrom@address.com”
$EmailTo = “emailt@address.com”
$Subject = “NSs Snapshots”
$SMTPServer = “smtp.address.com”

#Plink command that gets the snaps
$Body1 = plink -ssh IPADDRESS -batch -l LOCALNIMBLEUSER -pw $decrypted "snap --list --all | grep NSs"
$Body2 = plink -ssh IPADDRESS -batch -l LOCALNIMBLEUSER -pw $decrypted "snap --list --all | grep NSs"

#Sends email
Send-MailMessage -from $EmailFrom -to $EmailTo -subject $Subject -smtpserver $SMTPServer -body @"
SAN1 Snapshots
$Body1

SAN2 Snapshots
$Body2

"@

#Variable Cleanup
$securePass = 1234
$pass = 1234
$Ptr = 1234
$decrypted = 1234
$Body1=1234
$Body2=1234

1 REPLY 1
Mahesh202
HPE Pro

Re: Script to find NSs Snapshots

Hi Ryan

I would recommend our official toolkit (https://www.powershellgallery.com/packages/HPENimblePowerShellToolkit/3.0.0)But the method posted above looks ok too.

Hope this helps.!

Regards
Mahesh202

If you feel this was helpful please click the KUDOS! thumb below!

I work for HPE.
[Any personal opinions expressed are mine, and not official statements on behalf of Hewlett Packard Enterprise]

Accept or Kudo