Support Forum: Get Support for Patch My PC Products and Services

Home Updater (Free Updater) => Report Bugs and Issues (Free Home Updater) => Topic started by: rbuxcey on October 02, 2019, 06:17:06 AM

Title: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: rbuxcey on October 02, 2019, 06:17:06 AM
Hey PatchMyPC

I have an issue to report regarding the PowerShell Script that is being used to detect your pre-made SCCM applications.

Issue:
Particular machines trying to deploy an application are reporting an error code of 0xffffffff. The Error Description in SCCM for the deployment is 'Script execution failed with error code -1'

Symptoms:
The AppDiscovery.log file on the affected machines display the error in more detail, stating:

In-line script returned error output: Get-ItemProperty : Specified cast is not valid.
At C:\Windows\CCM\SystemTemp\9f53767d-d483-4ff6-9523-d65e723a65d6.ps1:103
char:5
+     Get-ItemProperty $regpath | .{process{if($_.DisplayName -and
$_.UninstallStr ...


In reference to the particular line of the script, it is trying to run:
Get-ItemProperty $regpath | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Select-Object DisplayName, DisplayVersion, UninstallString, PSChildName, Publisher, InstallDate | Sort DisplayName

Cause:
The problem, as reported on GitHub (see: https://github.com/majkinetor/au-packages/issues/15) is that Get-ItemProperty cannot interpret invalid DWORD entries. On the affected machines, due to bespoke custom applications installed, invalid DWORD entries exist within the Uninstall areas of the registry. Therefore, the script fails at this point and fails to evaluate whether the app is installed, thus preventing it from being deployed.

Because we allow software to be freely installed, there is an infinite possibility that an application generating a bad DWORD registry entry can be installed to any of our machines. This would stop ANY PatchMyPC application from deploying, as this part of the script is generic.

Can a fix be implemented for this please? I have attached images for reference.
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: Justin Chalfant (Patch My PC) on October 02, 2019, 08:47:57 AM
What is the version of PatchMyPC-ScriptRunner.exe in the app source files?
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: Justin Chalfant (Patch My PC) on October 02, 2019, 03:40:40 PM
We have a new private build (1.5.3.3) that we believe should help with this scenario. Can you test the preview build by downloading the MSI here https://patchmypc-my.sharepoint.com/:u:/p/support/EVy8KUZy011LkoMVLgGFQCsBpXpt_klaTiZJXaIb1gglZA?e=zSOng0

Please delete the applications having this issue as described here:

How to Delete Applications Created by Patch My PC in SCCM - https://patchmypc.com/how-to-delete-applications-created-by-patch-my-pc-in-sccm

And run a sync to have it re-create and test it the detection method script works.
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: rbuxcey on October 03, 2019, 07:49:38 AM
Heya

So on some machines that has been fixed with this preview. However I have noticed a different error occurring on some machines, which still presents the 0xfffffff error code.

AppDiscovery reports the following:

In-line script returned error output: Get-ItemProperty : The member "UninstallString" is already present.
At C:\Windows\CCM\SystemTemp\4ac20652-7723-43df-b9fe-0e3a51c6a08a.ps1:105 char:
21
+     Get-ItemProperty <<<<  $regpath -Name $propertyNames -ErrorAction Silentl
yContinue | .{process{if($_.DisplayName -and $_.UninstallString) { $_ } }} | Se
lect-Object DisplayName, DisplayVersion, UninstallString, PSChildName, Publishe
r, InstallDate | Sort DisplayName
    + CategoryInfo          : NotSpecified: (:) [Get-ItemProperty], ExtendedTy
   peSystemException
    + FullyQualifiedErrorId : AlreadyPresentPSMemberInfoInternalCollectionAdd,
   Microsoft.PowerShell.Commands.GetItemPropertyCommand


I have attached an image for reference.

Russell
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: Justin Chalfant (Patch My PC) on October 03, 2019, 08:05:21 AM
Can you export both your Uninstall keys:

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

And email it as ZIP here https://patchmypc.com/technical-support.
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: rbuxcey on October 04, 2019, 12:15:53 AM
I have just emailed them over, taken from an example machine with the issue :)
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: Justin Chalfant (Patch My PC) on October 04, 2019, 05:01:25 AM
Can you try this internal build? https://patchmypc-my.sharepoint.com/:u:/p/support/EeD6uagDAl9KqGo5AlD4T3IB8Ygwf1Qh1cVnru0_RrtHLQ?e=L9Y1Ft

You will need to delete the app and re-create it to test the fix.
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: rbuxcey on October 04, 2019, 07:54:14 AM
Having tried that, I now see a new issue:

    In-line script returned error output: Method invocation failed because [System.Version] doesn't contain a method name
d 'Parse'.
At C:\Windows\CCM\SystemTemp\6dcf40f1-e8ac-4aa1-aaae-b9ffa2ffa7cc.ps1:118 char:
35
+     return [System.Version]::Parse <<<< ("0.0.0.0")
    + CategoryInfo          : InvalidOperation: (Parse:String) [], RuntimeExce
   ption
    + FullyQualifiedErrorId : MethodNotFound

Method invocation failed because [System.Version] doesn't contain a method name
d 'Parse'.
At C:\Windows\CCM\SystemTemp\6dcf40f1-e8ac-4aa1-aaae-b9ffa2ffa7cc.ps1:118 char:
35
+     return [System.Version]::Parse <<<< ("0.0.0.0")
    + CategoryInfo          : InvalidOperation: (Parse:String) [], RuntimeExce
   ption
    + FullyQualifiedErrorId : MethodNotFound

You cannot call a method on a null-valued expression.


I have attached another screenshot.

Russell
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: David Courtel (Patch My PC) on October 04, 2019, 08:16:51 AM
What is the PowerShell version?
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: rbuxcey on October 04, 2019, 09:19:21 AM
It should be Powershell 5.0 as most machines are currently on Windows 10 1709.
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: Justin Chalfant (Patch My PC) on October 04, 2019, 09:20:34 AM
Was that machine in the screenshot PowerShell 5?
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: rbuxcey on October 04, 2019, 10:23:34 AM
Apologies - I have just double checked and this machine is actually a Windows 7 PC. The other machine experiencing this problem as well is also Windows 7. So the version of Powershell will be older, likely 2.0
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: Justin Chalfant (Patch My PC) on October 04, 2019, 11:47:00 AM
The parse bug for PowerShell 2.0 should be fixed in this internal build https://patchmypc-my.sharepoint.com/:u:/p/support/EQdRn91O-79Hv5yUlvFWv7cBfP-H9M2wyQAB4XXHvM0J5A?e=4wNSds

Could you test for us you will need to delete the SCCM app + source files and run a sync to re-create it.

Quote from: rbuxcey on October 04, 2019, 10:23:34 AM
Apologies - I have just double checked and this machine is actually a Windows 7 PC. The other machine experiencing this problem as well is also Windows 7. So the version of Powershell will be older, likely 2.0
Title: Re: Specified Cast is not valid - Issue with PowerShell Script Detection Method
Post by: rbuxcey on October 07, 2019, 01:28:49 AM
Thats appears to have fixed the issue - thank you!