0

I would like to edit Win32_Product install date using PowerShell, I tried this script (runned as Administrator):

$tmp = Get-WmiObject -Class Win32_Product -ComputerName . | Where-Object -FilterScript {$_.Name -eq "Software Name"}
$tmp.InstallDate="20170305"
$tmp.put()

But it is telling me there is missing arguments in put(). I checked and the $tmp content the good Object, but I can't edit it. How can I do it ?

1 Answers1

1

When in doubt, read the documentation:

InstallDate

    Data type: string
    Access type: Read-only

Emphasis mine.

If you must fake the install date (for whatever obscure reason) you must do so directly in the registry.

Set-ItemProperty 'HKLM:\path\to\uninstall\key' 'InstallDate' '20170305'
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Ok thanks, but when I edit registry and then get the WmiObject, I still have the same date, even if the InstallDate registry entry is changed – user2663781 Mar 06 '17 at 22:47
  • 1
    @user2663781 The simple answer is to stop using `Win32_Product` and query the reg key each time anyways. Every time you call the WMI class, it does a verification on every installed msi.... – BenH Mar 06 '17 at 22:49
  • 1
    Indeed, [`Win32_Product` is evil](https://gregramsey.net/2012/02/20/win32_product-is-evil/) and should be avoided entirely. – Ansgar Wiechers Mar 07 '17 at 00:18
  • ^ He is correct, never use `Win32_Product`. [Query the registry instead](https://stackoverflow.com/questions/71575378/powershell-for-software-inventory/71576041#71576041) for your software inventory needs. – codewario Mar 24 '22 at 14:20