none
"Null Array" RRS feed

  • Question

  • I am attempting to write a simple PowerShell script that uses WMI to query Adobe Air, uninstall and log the event. When I  run;

    Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "Adobe Air"} the ID is returned but when I run the entire script

    $product = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "Adobe Air"}
    
    Start-Sleep -s 10
    
    $AppGUID = $product.properties["IdentifyingNumber"].value.toString()
    
    MsiExec.exe /norestart /q/x /l*v "C:\IT\Service Desk Tools\Logs\Air_Uninstall.log" $AppGUID REMOVE=ALL 

    It returns an error;

    Cannot index into a null array.
    At line:5 char:32
    + $AppGUID = $product.properties[ <<<< "IdentifyingNumber"].value.toString()
        + CategoryInfo          : InvalidOperation: (IdentifyingNumber:String) [], RuntimeException
        + FullyQualifiedErrorId : NullArray


    DHeinz

    • Moved by Bill_Stewart Wednesday, December 12, 2018 8:21 PM This forum is not personal help desk for your deployment issues
    Wednesday, August 29, 2018 1:40 PM

All replies

  • Does this work?

    $product = @(Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "Adobe Air"})

    It forces $product to be an array even if there is only one object in it.

    Wednesday, August 29, 2018 1:57 PM
  • Hi,

    When Get-WmiObject does not return any results, the $project variable is empty. You cannot index into the property ($AppGUID = $product.properties["IdentifyingNumber"].value.toString()), because it is empty.

    Check if the variable is not null or empty before executing the other cmdlets.

    (Btw, you don't need the Start-Sleep either, because command execution is paused until Get-WmiObject returns the value to the $project variable)

    $product = Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -like "Adobe Air"}
    
    if ($product) {
        $AppGUID = $product.properties["IdentifyingNumber"].value.toString()
    
        MsiExec.exe /norestart /q/x /l*v "C:\IT\Service Desk Tools\Logs\Air_Uninstall.log" $AppGUID REMOVE=ALL
    }

    Best regards,

    John

    Wednesday, August 29, 2018 2:31 PM
  • if($product = Get-WmiObject Win32_Product -Filter 'Name like "%Adobe Air%"'){
        $appGUID = $product.IdentifyingNumber
        MsiExec.exe /norestart /q/x /l*v "C:\IT\Service Desk Tools\Logs\Air_Uninstall.log" $appGUID REMOVE=ALL
    }else{
        Write-Host 'Adobe Air not found'
    }
    Does not account for multiple versions of "AIR" being installed.

    \_(ツ)_/



    • Edited by jrv Wednesday, August 29, 2018 6:12 PM
    Wednesday, August 29, 2018 6:10 PM