Quantcast
Channel: THWACK: All Content - All Communities
Viewing all articles
Browse latest Browse all 20202

Object not set to an instance of an object - Volumes

$
0
0

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"

}


Viewing all articles
Browse latest Browse all 20202

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>