Microsoft Virtualization Discussions

Powershell script to schedule Monthly SnapShots

kobusventer
4,484 Views

Hi

 

I hope someone can assist me please. I am now strugling for a few days to get a script to work. What I need to do is to create manual monthly snapshots, on all of the NetApp controllers in our environment, on all production volumes. This snapshots will then be mirrored to DR. 

 

I have done the following:

 

set executionpolicy remotesigned
Import-Module DataONTAP

#Get Current Date and Save in the format YYYY_MM_DD
$Date = Get-Date -UFormat "%Y_%m_%d"
$Date

#Set SnapShot Name
$SnapName = "monthly_backup_$Date"
$SnapName

#Connect to Filers and create SnapShot
$filers = (Get-Content C:\Users\xxxxxxxxxx\Documents\filer_IP_list_toets.txt)

Foreach ($filer in $filers)
{

Connect-NAController $filer -Credential root

Get-NaVol $volName | New-NaSnapshot $SnapName
}

 

The output returns the following up to $SnapName

 

set executionpolicy remotesigned
Import-Module DataONTAP

#Get Current Date and Save in the format YYYY_MM_DD
$Date = Get-Date -UFormat "%Y_%m_%d"
$Date

#Set SnapShot Name
$SnapName = "monthly_backup_$Date"
$SnapName

#Connect to Filers and create SnapShot
$filers = (Get-Content C:\Users\xxxxxxxxxx\Documents\filer_IP_list_toets.txt)

Foreach ($filer in $filers)
{

Connect-NAController $filer -Credential root

Get-NaVol $volName | New-NaSnapshot $SnapName
}

2018_10_03 ($Date)
monthly_backup_2018_10_03 ($SnapName)

 

Then it asks for authentication:

 

return the following output:

 

Name                                 Address                        Ontapi               Version
---- ------- ------ -------
xxx.xxx.xxx.xxx              xxx.xxx.xxx.xxx                 1.21                NetApp Release 8.2.3     P2 7-Mode: Wed Mar 4 19:06:11 PST 2015

 

 

New-NaSnapshot : The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take pipeline input.
At line:20 char:22
+ Get-NaVol $volName | New-NaSnapshot $SnapName
+ ~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (CZ1029_vol0:PSObject) [New-NaSnapshot], ParameterBindingException
+ FullyQualifiedErrorId : InputObjectNotBound,DataONTAP.PowerShell.SDK.Cmdlets.Snapshot.NewNaSnapshot

 

 

It seems that the string cannot accet a pipe command? 

 

Any ideas how I can get this working? I suppose it is something small that I am overlooking.

 

Regards

 

 

 

 

2 REPLIES 2

kobusventer
4,473 Views

Windows PowerShell Integrated Scripting Environment ISE | Microsoft Docs

PowerShell 3.0 (Windows Server 2012

JGPSHNTAP
4,468 Views

First it doesn't look like you are using a credentials object so it's going to prompt you each time...

 

Check out man connect-nacontroller.

 

it doesn't appear that you have a variable for $volName .

 

 

Public