Search notes:

PowerShell cmdLet Set-ItemProperty

Creating or modifying a registry value

set-itemProperty allows to create or modify a registry value.
The parameter -type specifies the data type with which the new value is created. The value domain for this parameter is found in the Microsoft.Win32.RegistryValueKind enum.
The following example creates the two registry values foo and bar under HKCU\Software\TQ84:
$regKey = 'hkcu:\Software\TQ84'

if (! (test-path $regKey )) {
   $null = new-item $regKey
}

set-itemProperty      `
   $regKey            `
  -name    foo        `
  -type    dWord      `
  -value   42

set-itemProperty      `
   $regKey            `
  -name    bar        `
  -type    string     `
  -value  'hello World'
Github repository about-PowerShell, path: /cmdlets/itemProperty/set/registry-value.ps1
After running the script, regedit.exe displays:
See also manipulating the registry with PowerShell.

Simulating the shell touch command

set-itemProperty can be used to simulated the shell touch command to change a file's last write time:
$fileName = 'test'

set-content $fileName 'foo bar baz'

set-itemProperty $fileName lastWriteTime (get-date '2001-02-03T04:05:06')

get-item $fileName
#
#       Directory: C:\Users\r.nyffenegger\github\temp\PowerShell\cmdLets\itemProperty\set
#   
#   Mode                 LastWriteTime         Length Name
#   ----                 -------------         ------ ----
#   -a---          03.02.2001    04:05             13 test
Github repository about-PowerShell, path: /cmdlets/itemProperty/set/touch.ps1
Alternatively, the last modification time etc. can also be altered like so:
$f = get-item c:\users\rene\xyz.txt
$f.lastAccessTime = new-object dateTime 2020,08,28,22,23,01
$f.lastWriteTime  = new-object dateTime 2001,02,03,04,05,06
$f.creationTime   = (get-date).addDays(-5)

See also

The command parameter -credential.
Powershell command noun: itemProperty

Index