none
Problem WMI script RRS feed

  • Question

  • Hi! I have a problem on the line 59 of the code , I try whit this two option unsuccessfully :

    'Tamaño' = $disco.size / 1gb -as [Long];

    'Tamaño' = $disco.size / 1gb -as [int];

    the size of the disk in byte is 227477024768 more than a int supports

    thanks !!!!

    http://poshcode.com/paste/951/


    • Edited by LaTOO Thursday, February 13, 2014 3:06 PM
    Thursday, February 13, 2014 2:43 PM

Answers

  • One thing that may be biting you here is that $disco will be an array, if you have multiple fixed disks on the computer.  You're treating it as though it's a single object in your code.  The same is true of Win32_Processor and Win32_NetworkAdapterConfiguration.

    You'll probably need to adjust your output object's structure (and the code that creates it) so that you can properly support multiple results for these classes.  For example:

    $pc = [ordered] @{
        # ...
    
        'Discos' = @(
            $disco | Select-Object -Property @(
                @{Name = 'Etiqueta Disco'; Expression = { $_.DeviceID } }
                @{Name = 'Tamaño'; Expression = { $_.Size / 1GB } }
            )
        )
    
        # ...
    }

    • Marked as answer by LaTOO Thursday, February 13, 2014 4:21 PM
    Thursday, February 13, 2014 4:08 PM

All replies

  • The "DeviceID" property is going to be your drive letter ("C:", etc), not a number.  Dividing a string by 1gb doesn't make sense.
    Thursday, February 13, 2014 3:02 PM
  • Try [UInt64].

    Also you don't need ; character at the end of your lines.

    Bill

    Thursday, February 13, 2014 3:03 PM
    Moderator
  • wrote bad... sorry the property is .size

    'Tamaño' = $disco.size / 1gb -as [Long];

    'Tamaño' = $disco.size / 1gb -as [int];

    Thursday, February 13, 2014 3:08 PM
  • You shouldn't need to use the -as operator here at all.  Whether $disco.size is a 32-bit or 64-bit number, you can still divide it by 1GB.  PowerShell will take care of any necessary implicit casting for you:

    PS C:\source\Temp> [int64]::MaxValue / 1gb
    8589934592
    
    PS C:\source\Temp> [int32]::MaxValue / 1gb
    1.99999999906868

    Thursday, February 13, 2014 3:16 PM
  • You shouldn't need to use the -as operator here at all.  Whether $disco.size is a 32-bit or 64-bit number, you can still divide it by 1GB.  PowerShell will take care of any necessary implicit casting for you:

    PS C:\source\Temp> [int64]::MaxValue / 1gb
    8589934592
    
    PS C:\source\Temp> [int32]::MaxValue / 1gb
    1.99999999906868

    this was very helpful to me,buttt in the code does not work

    the code now is this http://poshcode.com/paste/963/


    • Edited by LaTOO Thursday, February 13, 2014 3:42 PM
    Thursday, February 13, 2014 3:42 PM
  • One thing that may be biting you here is that $disco will be an array, if you have multiple fixed disks on the computer.  You're treating it as though it's a single object in your code.  The same is true of Win32_Processor and Win32_NetworkAdapterConfiguration.

    You'll probably need to adjust your output object's structure (and the code that creates it) so that you can properly support multiple results for these classes.  For example:

    $pc = [ordered] @{
        # ...
    
        'Discos' = @(
            $disco | Select-Object -Property @(
                @{Name = 'Etiqueta Disco'; Expression = { $_.DeviceID } }
                @{Name = 'Tamaño'; Expression = { $_.Size / 1GB } }
            )
        )
    
        # ...
    }

    • Marked as answer by LaTOO Thursday, February 13, 2014 4:21 PM
    Thursday, February 13, 2014 4:08 PM
  • One thing that may be biting you here is that $disco will be an array, if you have multiple fixed disks on the computer.  You're treating it as though it's a single object in your code.  The same is true of Win32_Processor and Win32_NetworkAdapterConfiguration.

    You'll probably need to adjust your output object's structure (and the code that creates it) so that you can properly support multiple results for these classes.  For example:

    $pc = [ordered] @{
        # ...
    
        'Discos' = @(
            $disco | Select-Object -Property @(
                @{Name = 'Etiqueta Disco'; Expression = { $_.DeviceID } }
                @{Name = 'Tamaño'; Expression = { $_.Size / 1GB } }
            )
        )
    
        # ...
    }

    GREAT!!! it's true ... I had not seen! thank you!!!!
    Thursday, February 13, 2014 4:21 PM