locked
Set-ItemProperty Example Code doesn't Work RRS feed

  • Question

  • Hi,

    I'm trying to use the "Set-ItemProperty" cmdlet to create/configure some registry entries on Windows 10 per the instructions from the following page:

    https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-itemproperty?view=powershell-5.1

    The suggested syntax and example code does not work. PowerShell produces voluminous output indicating it cannot find the resource, when it should be creating it (according to the docs).

    My code

    #Disable Consumer Features
    Get-PSDrive -PSProvider Registry
    echo "Disabling consumer features"
    Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\CloudContent -Name DisableWindowsConsumerFeatures -Value 0

    Output

    Set-ItemProperty : Cannot find path 'HKLM:\Software\Policies\Microsoft\Windows\CloudContent' beca
    At C:\Users\jasonrw\Documents\Scripts\DSC_Win10_Local_GPO.ps1:8 char:1
    + Set-ItemProperty -Path HKLM:\Software\Policies\Microsoft\Windows\Clou ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (HKLM:\Software\...ws\CloudContent:String) [Set-Ite
       undException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand

    PowerShell IS being run as an administrator. I'm copying/pasting into a text editor, saving as PS1 and running from the shell. I have no idea why this is not working.

    Thanks


    Jason

    Wednesday, January 31, 2018 4:59 PM

Answers

  • You can create registry values with set-itemproperty, not registry keys.  Create registry keys with 'new-item', not 'new-itemproperty'.


    Item = registry key
    ItemProperty = registry value
    ItemPropertyValue = registry data


    • Marked as answer by N74JW Wednesday, January 31, 2018 7:03 PM
    • Edited by JS2010 Wednesday, January 31, 2018 8:55 PM
    Wednesday, January 31, 2018 6:35 PM

All replies

  • Have to create the registry key if it doesn't already exist.  

    New-Item -Path HKLM:\Software\Policies\Microsoft\Windows\CloudContent

    Wednesday, January 31, 2018 5:35 PM
  • That fails too. Besides, why do the docs indicate the Set command will create the entry?

    Jason

    Wednesday, January 31, 2018 5:48 PM
  • Output
    Name           Used (GB)     Free (GB) Provider      Root
    ----           ---------     --------- --------      ----
    HKCU                                   Registry      HKEY_CURRENT_USER
    HKLM                                   Registry      HKEY_LOCAL_MACHINE
    Disabling consumer features
    
    cmdlet New-ItemProperty at command pipeline position 1
    Supply values for the following parameters:
    Name: DisableWindowsConsumerFeatures
    New-ItemProperty : Cannot find path 'HKLM:\Software\Policies\Microsoft\Windows\CloudContent' bec
    At C:\Users\user\Documents\Scripts\DSC_Win10_Local_GPO.ps1:7 char:1
    + New-ItemProperty -Path "HKLM:\Software\Policies\Microsoft\Windows\Clo ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (HKLM:\Software\...ws\CloudContent:String) [New-It
       undException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.NewItemPropertyCommand
    
    Set-ItemProperty : Cannot find path 'HKLM:\Software\Policies\Microsoft\Windows\CloudContent' bec
    At C:\Users\user\Documents\Scripts\DSC_Win10_Local_GPO.ps1:8 char:1
    + Set-ItemProperty -force -Path "HKLM:\Software\Policies\Microsoft\Wind ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (HKLM:\Software\...ws\CloudContent:String) [Set-It
       undException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand


    Jason

    Wednesday, January 31, 2018 5:51 PM
  • You can create registry values with set-itemproperty, not registry keys.  Create registry keys with 'new-item', not 'new-itemproperty'.


    Item = registry key
    ItemProperty = registry value
    ItemPropertyValue = registry data


    • Marked as answer by N74JW Wednesday, January 31, 2018 7:03 PM
    • Edited by JS2010 Wednesday, January 31, 2018 8:55 PM
    Wednesday, January 31, 2018 6:35 PM
  • This syntax:

    New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\CloudContent

    Produces a prompt to which I am not sure what to answer.

    These:

    New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\CloudContent -Name ConfigureWindowsSpotlight
    Set-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\CloudContent -Name ConfigureWindowsSpotlight -Value 1
    New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\CloudContent -Name IncludeEnterpriseSpotlight
    Set-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\CloudContent -Name IncludeEnterpriseSpotlight -Value 1

    Error as not found. Note, I'm trying to create the keys first.

    New-ItemProperty : Cannot find path 'HKCU:\Software\Policies\Microsoft\Windows\CloudContent' because it does not exist.
    At C:\Users\jasonrw\Documents\Scripts\PowerShell_Sucks.ps1:13 char:1
    + New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Clou ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (HKCU:\Software\...ws\CloudContent:String) [New-ItemProperty], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.NewItemPropertyCommand
    
    Set-ItemProperty : Cannot find path 'HKCU:\Software\Policies\Microsoft\Windows\CloudContent' because it does not exist.
    At C:\Users\jasonrw\Documents\Scripts\PowerShell_Sucks.ps1:14 char:1
    + Set-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Clou ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (HKCU:\Software\...ws\CloudContent:String) [Set-ItemProperty], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand
    
    New-ItemProperty : Cannot find path 'HKCU:\Software\Policies\Microsoft\Windows\CloudContent' because it does not exist.
    At C:\Users\jasonrw\Documents\Scripts\PowerShell_Sucks.ps1:15 char:1
    + New-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Clou ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (HKCU:\Software\...ws\CloudContent:String) [New-ItemProperty], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.NewItemPropertyCommand
    
    Set-ItemProperty : Cannot find path 'HKCU:\Software\Policies\Microsoft\Windows\CloudContent' because it does not exist.
    At C:\Users\jasonrw\Documents\Scripts\PowerShell_Sucks.ps1:16 char:1
    + Set-ItemProperty -Path HKCU:\Software\Policies\Microsoft\Windows\Clou ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : ObjectNotFound: (HKCU:\Software\...ws\CloudContent:String) [Set-ItemProperty], ItemNotFoundException
        + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand


    Jason

    Wednesday, January 31, 2018 6:36 PM
  • Answered above.

    Wednesday, January 31, 2018 6:52 PM
  • Awesome! Very helpful. What's the difference between New-ItemProperty and Set-ItemProperty?

    Jason

    Wednesday, January 31, 2018 7:03 PM
  • I'm not even sure.  Maybe just completeness with the verbs.

    Wednesday, January 31, 2018 7:06 PM
  • Awesome! Very helpful. What's the difference between New-ItemProperty and Set-ItemProperty?

    Jason

    New-ItemProperty Creates a new property for an item and sets its value.

    Set-ItemProperty Creates or changes the value of a property of an item.


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful. (99,108,97,121,109,97,110,50,64,110,121,99,97,112,46,114,114,46,99,111,109|%{[char]$_})-join''

    Wednesday, January 31, 2018 7:16 PM