Windiskcapacity

Welcome Forums Pester Windiskcapacity

This topic contains 1 reply, has 2 voices, and was last updated by

js
 
Participant
6 months, 1 week ago.

  • Author
    Posts
  • #98610

    Participant
    Points: 0
    Rank: Member

    have a basic knowledge of scripting. Not sure what the expanded data would be. When I run it keep getting an error below

    You cannot call a method on a null-valued expression.
    At C:\scripts\Get-WinDiskCapacity.ps1:26 char:1
    + $size = $size.Trim()
    + ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\scripts\Get-WinDiskCapacity.ps1:27 char:1
    + $size = $size.Substring(0,$size.Length-2)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.
    At C:\scripts\Get-WinDiskCapacity.ps1:30 char:8
    + return $size.Trim()
    + ~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    here is the script:

    # $expandeddata – The output from hpssacli to be parsed
    param(
    [Parameter(mandatory=$true)]
    [string]$expandeddata
    )

    # Test the parameter
    if($expandeddata -eq ""){
    return "[ERROR] The expandeddata passed to Get-WinDiskCapacity is empty!"
    }

    # Parse out the size of the disk
    if($expandeddata -match "Drive exposed"){
    $splited = $expandeddata -Split "Drive exposed"
    $rawsize = ($splited[0]) -Split "Size:"
    $size = $rawsize[1]
    }else{
    $splited = $expandeddata -Split "Native Block Size"
    $rawsize = ($splited[0]) -Split "Size:"
    $size = $rawsize[1]
    }
    $size = $size.Trim()
    $size = $size.Substring(0,$size.Length-2)

    # Send the disk size
    return $size.Trim()

  • #98718
    js

    Participant
    Points: 6
    Rank: Member

    What does the input look like? You'd have to give the string after the command. If you want to pipe to it, you have to use

    [parameter(Mandatory=$true,
        ValueFromPipeline=$true)]
    

    I think you can split on

    -split ': '
    

    if the input looks like this: https://github.com/glensc/nagios-plugin-check_raid/issues/174

The topic ‘Windiskcapacity’ is closed to new replies.