Microsoft Virtualization Discussions

PowerShelll Error: Method invocation failed because ....

rdenyer001
11,434 Views

All,

Very new to scripting/powershell    and have  a task to  move   many  viloumes from and old 7-mode filer  7.3.6  to a new filer  7 mode 8.2.2 (unfortunealty can't go cDOT)

 

Trying to write a script that will allow me to put in the name of the  volume on the old system and its size  and then have the script   create the volume on the new system and then complete the snap mirror initialize.

 

Here  is my script  ( made up of parts copied from various scripts found on the web)

 

## Controller Login Variables
Import-Module dataontap
$ntapuser = "XXXX"
$ntappw = "XXXX"
### Convert Password to plain text
$pw = convertto-securestring $ntappw -asplaintext -force
$cred = new-object -typename system.management.automation.pscredential -argumentlist $ntapuser,$pw

# Connect to Snapmirror Source and Destination
$SrcFiler = Connect-NaController XXXX -Credential $cred -https
$DestFiler = Connect-NaController XXXX -Credential $cred -https
#set volume name and size
$Vol = Read-Host 'Volume Name?'
$Size = Read-Host 'Volume Size?'
$Scr = $SrcFiler + ":" + $Vol

I get this error  Method invocation failed because [NetApp.Ontapi.Filer.NaController] doesn't contain a method named 'op_Addition
$Dest = $DestFiler + ":" + $Vol

and here 
# Create our destination volume
New-NaVol $Vol -Controller $DestFiler -Aggregate aggr0 -Size $Size -SpaceReserve none

I get this error here   New-NaVol : Object reference not set to an instance of an object.
At C:\Users\Richard\NewMirror2.ps1:18 char:1 + New-NaVol $Vol -Controller $DestFiler -Aggregate aggr0 -Size $Size -SpaceReserve

But the volume is created 
Set-NaVol -Name $Vol -Restricted -Controller $DestFiler

Same here Set-NaVol : Object reference not set to an instance of an object.
At C:\Users\Richard\NewMirror2.ps1:19 char:1  + Set-NaVol -Name $Vol -Restricted -Controller $DestFiler
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

but the volume is restricted


# Initialize Snapmirror
Invoke-NaSnapmirrorInitialize -Destination $Dest -Source $Scr

But then here,  this just fails   but I figure that  is more related to the first error  at line 15  and 16 

 

I have downloaed and installed latest toolkit 

have noticed that  results coming back from the new 8.2.2 system  (destination)   are a LOT slower than the old 7.3.6  system

Any help and or suggestions would be greatly appriciated .

 

Here is the total  out put from my powershell session

PS C:\Users\Richard> .\NewMirror2
Volume Name?: TestVOL
Volume Size?: 40g
Method invocation failed because [NetApp.Ontapi.Filer.NaController] doesn't contain a method named 'op_Addition'.
At C:\Users\Richard\NewMirror2.ps1:15 char:1
+ $Scr = $SrcFiler + ":" + $Vol
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [NetApp.Ontapi.Filer.NaController] doesn't contain a method named 'op_Addition'.
At C:\Users\Richard\NewMirror2.ps1:16 char:1
+ $Dest = $DestFiler + ":" + $Vol
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound

New-NaVol : Object reference not set to an instance of an object.
At C:\Users\Richard\NewMirror2.ps1:18 char:1
+ New-NaVol $Vol -Controller $DestFiler -Aggregate aggr0 -Size $Size -SpaceReserve ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (DC-XXX:NaController) [New-NaVol], NullReferenceException
+ FullyQualifiedErrorId : VolumeListInfoFailed,DataONTAP.PowerShell.SDK.Cmdlets.Volume.NewNaVol

Set-NaVol : Object reference not set to an instance of an object.
At C:\Users\Richard\NewMirror2.ps1:19 char:1
+ Set-NaVol -Name $Vol -Restricted -Controller $DestFiler
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (DC-XXX:NaController) [Set-NaVol], NullReferenceException
+ FullyQualifiedErrorId : VolumeListInfoFailed,DataONTAP.PowerShell.SDK.Cmdlets.Volume.SetNaVol

Invoke-NaSnapmirrorInitialize : Cannot bind argument to parameter 'Destination' because it is null.
At C:\Users\Richard\NewMirror2.ps1:22 char:45
+ Invoke-NaSnapmirrorInitialize -Destination $Dest -Source $Scr
+ ~~~~~
+ CategoryInfo : InvalidData: (:) [Invoke-NaSnapmirrorInitialize], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,DataONTAP.PowerShell.SDK.Cmdlets.Snapmirr
or.InvokeNaSnapmirrorInitialize

 

 

Regards,

Richard

8 REPLIES 8

HONIG2012
11,421 Views

hi richard,

 

let's start from top - what are you expecting when doing this?

>> $Scr = $SrcFiler + ":" + $Vol ??

 

i don't have a clue  about this

 

another thing what i remember to be heard is that you cannot have multiple controller connections at the same time - i think you have to connect to srcfiler first - create volume, set volume options and so on - and when you're done with the src - connect to the destination - create volume, set volume options, restrict volume and then initialize snapmirror - i think this should work.

 

let me know you meant and i'll try to assist.

 

thanks AJ

JGPSHNTAP
11,412 Views

Are you trying to do a one by one volume creation?  if so why?

 

I've used this is the past to create in bulk to mirror a setup

 


$sfiler = read-host "Enter Source Filer"
$dfiler = read-host "Enter Destination Filer"

 


#Production Testing

 

##Failover testing
$srcfiler= Connect-NaController $sfiler
$dstfiler= Connect-NaController $dfiler

#define aggr
$aggr = "aggr1"



$vols = Get-NaVol -Controller $srcfiler

## Loop through existing vols

 

foreach ($vol in $vols) {


$volume = $vol.name
$size = $vol.totalsize
# Create new Volumes on Destination Filer
New-NaVol -Name $volume -Aggregate $aggr -SpaceReserve none -Size $size -Controller $dstfiler -confirm:$false

#Set Volume Settings
Set-NaSnapshotReserve -TargetName $volume "0" -Controller $dstfiler

#Prepare volume for Snapmirror - Restrict volume
Set-NaVol -Name $volume -restricted -Controller $dstfiler

# Setup snapmirror up
Invoke-NaSnapmirrorInitialize -destination $dfiler":"$volume -Source $sfiler":"$volume -Controller $dstfiler

# Setup Snapmirror Schedule
Set-NaSnapmirrorSchedule -destination $dfiler":"$volume -Source $sfiler":"$volume -minutes "15" -hours "0-23/4" -daysofmonth * -daysofweek * -Controller $dstfiler



}

 

 

That will setup the volumes on the new target controller, and start snapmirrors

rdenyer001
11,355 Views

Thanks  JGPSHNTAP

 

This was my reasoning behind a script, as the IT  team could then decide which volumes to take to the new filer, and all they need to do was to enter the name of the volume and its size  and the  script  would do the rest.

Unfortunetaly  my script writing ability   does not keep up with my ideas , that why  I use the  community .

 

Thanks for your input  

rdenyer001
11,353 Views

AJ,

wwhat I was trying to  get  was a varible string that   I could I could use in the command   Invoke-NaSnapmirrorInitialize.

 

Thansk for you interest  looks like the answer has been provied  

 

RD

diwakar
10,982 Views

Hello RD,

 

               I am working with NetApp for few years but I never had the chance to work on Powershell before. I had been trying to get started with NetApp Powershell module for few days. I am able to connect to filers individually and run few cmdlets. But if I am having issues in connecting to multiple filers at once and list system info by using foreach loop in my profile. But surprisingly the same profile is working fine at times. By saying working , I am not getting any output but it runs without throwing any errors. You can see the loop I am talking about below:

 

foreach ($filer in $allfilers){
#connect to the storage system
Connect-NaController $filer -Credential $authentication
echo "Connecting to $filer"

echo "--------------"$filer"-------------"
get-nasysteminfo
}

 

In the above loop, should I give a pause or anything in order to get the filer info?  You can see the errors which I am getting below:

 

Connect-NaController : Object reference not set to an instance of an object.
At D:\Data\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:20 char:21
+ Connect-NaController <<<< $filer -Credential $authentication
+ CategoryInfo : InvalidResult: (filer1:NaController) [Connect-NaController], NullReferenceException
+ FullyQualifiedErrorId : HttpConnectionFailed,DataONTAP.PowerShell.SDK.ConnectNaController

 

Get-NaSystemInfo : Value in $global:CurrentNaController is not of type NetApp.Ontapi.Filer.NaController
At D:\Data\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:23 char:17
+ get-nasysteminfo <<<<
+ CategoryInfo : InvalidArgument: (:) [Get-NaSystemInfo], ArgumentException
+ FullyQualifiedErrorId : ControllerNotSpecified,DataONTAP.PowerShell.SDK.Cmdlets.System.GetNaSystemInfo

Connect-NaController : Object reference not set to an instance of an object.
At D:\Data\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:20 char:21
+ Connect-NaController <<<< $filer -Credential $authentication
+ CategoryInfo : InvalidResult: (filer2:NaController) [Connect-NaController], NullReferenceException
+ FullyQualifiedErrorId : HttpConnectionFailed,DataONTAP.PowerShell.SDK.ConnectNaController

 

Any information in this regard would be really helpfull. Thank you very much in advance.

 

Thanks,

MD.

 

JGPSHNTAP
10,969 Views

Can you please start a new thread as its easier to monitor

markweber
11,405 Views

$SrcFiler and $DestFiler aren't strings like you are expecting - they are objects.

use $SrcFiler.name for the controller name (or maybe assign the filer name to a variable and use that in the connect-nacontroller command and also later on in the snapmirror initialize)

 

connect-nacontroller $destination

invoke-snapmirror -destination $destination:$vol -source $source:$vol

 

m

 

rdenyer001
11,354 Views

Thanks Mark

Will give this  a go

 

 

Public