Windiskcapacity

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: (:slight_smile: [], 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()

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