Author Posts

January 1, 2012 at 12:00 am

by Sum4uandSum4u at 2012-10-15 14:24:51

Thanks in Advance!

Here is the code:
I want to gather the value of the below variable... It looks like I need to somehow convert the com value to something else before I check it, based on the error below.? I have not clue how to do that!

$Sheet3.Cells.Item($intRowDisk, 4) = $objItem.Size/1024/1024/1024 - $objItem.FreeSpace/1024/1024/1024

Then I want to compare that value and if it is larger than 100 GB place a value of yes or no in a column within an excel spreadsheet.

if ( $Sheet3.Cells.Item($intRowDisk, 4) -gt 100 ) {
$Sheet1.Cells.Item($intRow, 12) = "Yes"

But I get the error of : ERROR: Bad argument to operator '-gt': Could not compare "System.__ComObject" to "100". Error: "Cannot convert the "100" value of type "System.Int32" to type "System.
ERROR: __ComObject".".
IME_InventoryV1.8.ps1 (124): ERROR: At Line: 124 char: 49
ERROR: + if ( $Sheet3.Cells.Item($intRowDisk, 4) -gt < <<< 100 ) {
ERROR: + CategoryInfo : InvalidOperation: (:) [], RuntimeException
ERROR: + FullyQualifiedErrorId : BadOperatorArgument

by Sum4uandSum4u at 2012-10-15 15:36:22

I figured it out.

I had to create a new variable and then I could present it to the IF function. IT works like a charm!

by nohandle at 2012-10-16 02:58:00

Hi,
you pass an object to the condition, but you should pass a value of integer type. Use $Sheet3.Cells.Item($intRowDisk, 4).Value() to retrieve the value of the cell.