3 Replies Latest reply on Aug 6, 2014 11:06 AM by dkeyser

    Object not set to an instance of an object - Volumes

    dkeyser

      Working on adding volumes with my script and it used to work when I fed it the wrong NodeID. Well I fixed that but now it's returning an error of 'Object reference not set to an instance of an object'. I've check this over and over and I can't see why it's erroring out. I've also looked at $Error[0] and it says 'New-SwisObject : Cannot bind argument to parameter 'Properties' because it is null.' The code I am using is a modified version of someone elses. Can't find it readily to give credit where credit is due.

       

      Also any comments on how to steamline the code please feel free!

       

      #Adding of Volumes

      ###############################################################

      function AddVolumes ($NewNodeID, $VolumeInfo, $Pollers)

      {

      Write-Host "Entering AddVolumes function"

      $VolNodeID = $NewNodeID.GetValue(1)

          foreach ($Volume in $VolumeInfo)

          {

                  $VolumeIndex = $Volume.VolumeIndex

                  $VolumeIndex

                  $VolumeType = $Volume.VolumeType

                  $VolumeType

                  $VolumeDescription = $Volume.VolumeDescription

                  $VolumeDescription

                 

                  Switch ($VolumeType){

                  0{$VolumeTrueType = @('Unknown','Unknown')}

                  1{$VolumeTrueType = @('Other', 'Other')}

                  2{$VolumeTrueType = @('RAM', 'RAM')}

                  3{$VolumeTrueType = @('Virtual Memory', 'VirtualMemory')}

                  4{$VolumeTrueType = @('Fixed Disk', 'LocalDisk')}

                  5{$VolumeTrueType = @('Removable Disk', 'RemovableDisk')}

                  6{$VolumeTrueType = @('Floppy Disk', 'FloppyDisk')}

                  7{$VolumeTrueType = @('Compact Disk', 'CompactDisk')}

                  8{$VolumeTrueType = @('RAM Disk', 'RamDisk')}

                  }

                  $VolumeTrueType

                 

                 

                  $newVolProps = @{

       

       

                  NodeID=$VolNodeID;

       

       

                  VolumeIndex=[int]$VolumeIndex;

       

       

                  Status=0;

       

       

                 VolumeType =$VolumeTrueType.GetValue(0);

                

                 VolumeTypeID = [int]$VolumeType;

       

       

                  VolumeTypeIcon =$VolumeTrueType.GetValue(1)+".gif";

       

       

      #            Caption="/";

       

       

                  VolumeDescription=$VolumeDescription;

       

       

                  PollInterval=120;

       

       

                  StatCollection=15;

       

       

                  RediscoveryInterval=30;

       

       

      #            NextRediscovery=[DateTime]::UtcNow;

       

       

                  }

       

       

              $newVolUri = New-SwisObject $swis -EntityType "Orion.Volumes" -Properties $newVolProps

       

       

              $newVolUri

       

       

              $VolProps = Get-SwisObject $swis -Uri $newVolUri

       

       

              foreach ($pollerType in @('V.Status.SNMP.Generic','V.Details.SNMP.Generic','V.Statistics.SNMP.Generic'))

                      {

       

       

                  $poller = @{

       

       

                      PollerType=$pollerType;

       

       

                      NetObject="V:"+$VolProps["VolumeID"];

       

       

                      NetObjectType="V";

       

       

                      NetObjectID=$VolProps["VolumeID"];

       

       

                      }

       

       

                  $pollerUri = New-SwisObject $swis -EntityType "Orion.Pollers" -Properties $poller

       

       

                   }

       

       

              # Trigger a PollNow on the node to cause other properties and stats to be filled in

       

       

              Invoke-SwisVerb $swis Orion.Nodes PollNow @("N:" + $VolNodeID)

       

       

          }

          Write-Host "Exiting addVolumes function"

      }

        • Re: Object not set to an instance of an object - Volumes
          juniordev

          I experienced "NextRediscovery" must any "not null" value. And probably, the problem is, the one of values at properties section is null. So, you didn't pass correctly values to properties. And maybe this thread is helpful for you.

          1 of 1 people found this helpful
            • Re: Object not set to an instance of an object - Volumes
              dkeyser

              Hello! Thank you for your help.

               

              I've added the NextRediscovery as the current time from the poller and also the VolumeSpaceAvailable stat but set it to 0 in hopes that it'll update the entry to the real space available after polling. I'm still getting the Object reference not set to an instance of an object error.

               

              Any other thoughts on this? Below are the volprops I've got currently.

                          NodeID=$VolNodeID;

               

               

                          VolumeIndex=[int]$VolumeIndex;

               

               

                          Status=0;

               

               

                          VolumeType =$VolumeTrueType.GetValue(0);

               

               

                          VolumeTypeID = [int]$VolumeType;

               

               

                          VolumeTypeIcon =$VolumeTrueType.GetValue(1)+".gif";

               

               

                          Caption="/";

               

               

                          VolumeDescription=$VolumeDescription;

               

               

                          PollInterval=120;

               

               

                          VolumeSpaceAvailable=0;

               

               

                          StatCollection=15;

               

               

                          RediscoveryInterval=30;

               

               

                          NextRediscovery=[DateTime]::UtcNow;

              • Re: Object not set to an instance of an object - Volumes
                dkeyser

                Haha! Figured out my issue! the first prop must not be an int or it's getting converted somewhere. By adding [int] in front of it I'm now adding all my volumes like a champ. Thank you very much for your assistance!