I want to preface this with I am fairly new to powershell.
We are trying to monitor a DFS share size across multiple end points and I have a powershell script using robocopy working locally. We cannot use the native get-childitem due to longfile names.
Below is the script, when testing against a node it is returning the message portion properly, but it is not returning the statistic (folder size). I have broken the script down into multiple steps to identify where it is failing and discovered it is not populating the $size variable. Again, it works perfectly when running locally from the Orion server (adding the ip manually), but returns null when running from SW template. When testing with "Get Script Output" it just returns 0 for the statistic.
Any ideas on what I am missing? Is this beyond the solarwinds powershell monitor capabilities or am I going about this incorrectly?
[string] $hostname = "${IP}"
[string] $strDir = "\\$hostname\share_name\tools"
$size = (robocopy $strDir 'NULL' /L /E /NP /NFL /NDL /bytes /njh | find "Bytes :")
$sizeb = $size.trim().split(" ")[2]
$sizec = $sizeb/1MB
$sized = [math]::round(${sizec},2)
write-host "Message.Size: ${strDir}"
write-host "Statistic.Size: ${sized}"
exit 0
This is the error I am getting when testing
Output: ==============================================
Message.Size: \\ip_address\share_name\tools
Statistic.Size: 0
Errors: ==============================================
You cannot call a method on a null-valued expression.
At line:5 char:1
+ $sizeb = $size.trim().split(" ")[2]
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull