New-ItemProperty creates string instead of DWord when run via GPO
the code below works expected when run via elevated cli, creating appropriate dword entry if necessary, or changing value 1.
the same code works when run via login or startup gpo, except creates string value instead of dword value.
i stumped. in advance can provide here.
$revision = 3 #working ## initialize event logging $eventlog = new-object system.diagnostics.eventlog('application') $eventlog.machinename = "." $eventlog.source = "script" ## send start message event log $eventlog.writeentry("[enablelinkedconnections][1]" + "registry editing has begun!") # create new 32-bit dword key\value if don't exist if ($(test-path hklm:\software\microsoft\windows\currentversion\policies\system\enablelinkedconnections) -eq "false") { new-itemproperty "hklm:\software\microsoft\windows\currentversion\policies\system" -name "enablelinkedconnections" -value 1 -propertytype "dword" $eventlog.writeentry("[enablelinkedconnections][2]" + "enablelinkedconnections not found , created.") } else { # set value if exist set-itemproperty "hklm:\software\microsoft\windows\currentversion\policies\system" -name "enablelinkedconnections" -value 1 } $eventlog.writeentry("[enablelinkedconnections][3]" + "registry editing has finished. bam!")
replace:
if ($(test-path hklm:\software\microsoft\windows\currentversion\policies\system\enablelinkedconnections) -eq "false") if (!(test-path hklm:\software\microsoft\windows\currentversion\policies\system\enablelinkedconnections)) or change "false" $false,because condition of comparison false , run set-itemproperty
Windows Server > Windows PowerShell
Comments
Post a Comment