Microsoft Virtualization Discussions

Powershell Script Help


Hi all

I have modified a script written by the forum member Chris Lionetti to check the options of an array of target servers and report on the diffrences compared to the Master server, Ive imported the module but the script will not run as a scheduled task and keeps throwing up this message below, not sure if the credentials loop is not right, if I invoke it manually it does work and creates the xlsx file but I have to run the script twice after manually running import-moduel DataONTAP?

Any ideas anyone?


Connect-NaController : Cannot bind argument to parameter 'Name' because it is n
At C:\Windows\System32\WindowsPowerShell\v1.0\Modules\DataONTAP\script2.ps1:19
+ Connect-NaController <<<<  $TargetController -Credential $Tcred
    + CategoryInfo          : InvalidData&colon; (:) [Connect-NaController], Paramet
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,D

Get-NaOption : Value cannot be null.
Parameter name: Controller parameter neither specified nor set in $global:Curre
At C:\Windows\System32\WindowsPowerShell\v1.0\Modules\DataONTAP\script2.ps1:21
+ $suppress = $Targops = get-naoption <<<<
    + CategoryInfo          : InvalidArgument: (:) [Get-NaOption], ArgumentNul
    + FullyQualifiedErrorId : ControllerNotSpecified,DataONTAP.PowerShell.SDK.

Script File

import-module DataONTAP

$workingController = "Masterserverfiler"
$targetControllers= @("server1","server2")
$User = "xxx"
$Pass = "xxx"

$WCPass  = ConvertTo-SecureString $Pass -AsPlainText –Force
$Wcred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$WCPass
$TCPass  = ConvertTo-SecureString $Pass -AsPlainText –Force
$Tcred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User,$WCPass
$workops=new-object system.collections.arraylist
Connect-NaController $TargetController -Credential $Tcred

$suppress = $Targops = get-naoption
Write-host "------------------------------------------------"

$excel=new-object -comobject excel.application

$worksheet.cells.item(1,1)="Option Name"
$worksheet.cells.item(2,1)="Controller Name"
$worksheet.cells.item(1,2)="Master FAS"
foreach($Controller in $TargetControllers)

{          Connect-NaController $Controller -Credential $Wcred
          $Workops.add( (get-naoption  ) )
           $worksheet.cells.item(1,$cellr)="Target FAS"
$worksheet.cells.item(1,$cellr)="Command to fix"

Write-host "------------------------------------------------"
foreach ($workop in $workops)
{     $coun=$coun+1
      foreach ($item in $workop)
      {      $workname=$
            $workval =$item.value
            foreach($titem in $targops)
            {     if ($ -eq $
                  {      $line=$line+1
                        write-host "   "$"="$item.value    
                        if ($titem.value -ne $item.value)
                        {      write-host "   "$"="$item.value" -Values Mismatch ="$titem.value
                              $worksheet.cells.item($line,$cellr)=("set-naoption"+$" "+$item.value)
                              write-host "        To fix this issue, command is as follows;"
                              write-host "           set-naoption"$""$item.value
$workdoc.EntireColumn.Autofit() | out-null


Re: Powershell Script Help


I have not tried the rest of the script, but try this to correct the first error that you are getting.


Connect-NaController $TargetController -Credential $Tcred


ForEach ($Controller in $TargetController){Connect-NaController $Controller -Credential $Tcred}

Also, it may be an issue of trying to load Excel if the script is not running in an active session

Re: Powershell Script Help



i tried it thanks for that, and tried some of other variations but its still doesnt play ball, it only seems to work when I load the powershell shell command window  then type import-module DataONTAP and then execute the script, if I double click the script it just comes up with the same error.

If I put a single value in the array it does work and doesnt come up with the error so it seems it doesnt pass the credentials when there is more tha  one controller

This doesnt work

$targetControllers= @("server1","server2")

This works

$targetControllers= ("server1")

Re: Powershell Script Help



How do you schedule the script? Check this out......



Re: Powershell Script Help


btw. if you want to automaticaly load the ontap module follow the instructions.

Howto auto load DataONTAP Powershell:

open powershell

type "echo $profile"

output example: C:\Users\mscarpi\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

create the directory WindowsPowerShell and the Microsoft.PowerShell_profile.ps1 file

open the Microsoft.PowerShell_profile.ps1

add import-module DataONTAP

save and close the file

close powershell and start it again

check to verify that the module is loaded "get-module"

output should list DataONTAP

Re: Powershell Script Help



Thanks I already imported the module

PS C:\Windows\System32\WindowsPowerShell\v1.0> get-module

ModuleType Name                      ExportedCommands
---------- ----                      ----------------
Manifest   DataONTAP                 {Invoke-NaSnapmirrorThrottle, Resume-Nc...

But the script seems to ignore it, as I said It only works when you run it from the powershell console twice I think somethings is not right with the credential code passthrough when you have more than one target controller as it doesnt complain at all when there is only one controller

Re: Powershell Script Help


Hi All

Its now working like a treat, i removed the variable for the username and password for traget controllers and passed on the currently logged on credentials which has rights and now it runs as a task and no errors and corrected the varaible for the target controllers


ForEach ($Controller in $TargetController){Connect-NaController $Controller -Credential $Tcred}


ForEach ($Controller in $TargetControllers){Connect-NaController $Controller}

Thanks A lot for all your help

Earn Rewards for Your Review!
GPI Review Banner
All Community Forums