• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 621
  • Last Modified:

Powershell command works but script fails

I have a .ps1 file that I generated to add a registry key to extend the timeout length for Internet Explorer.

The command line work when run in PS, but when I convert it to a script it fails with the following error;

"New-ItemProperty : The property already exists.
At C:\Users\Dmaranya\IE_Timeout_Adjust.ps1:3 char:1
+ New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet ...
    + CategoryInfo          : ResourceExists: (HKEY_LOCAL_MACH...ternet Settings:String) [New-ItemProperty], IOExcepti
    + FullyQualifiedErrorId : System.IO.IOException,Microsoft.PowerShell.Commands.NewItemPropertyCommand

Anyone know why the command line works but the script doesn't?
1 Solution
Does the property already exist?  Are you using the -force parameter?

Care to share the script?
Mdamon808Author Commented:
Oops, it appears that I neglected to upload the file with my question. My bad, here it is.
WEBINAR: GDPR Implemented - Tips & Lessons Learned

Join the WatchGuard team on Thursday, March 29th as we recount some valuable lessons learned in weighing the needs of a business against the new regulatory environment, look ahead at the two months left before implementation, and help you understand the steps you can take today!

Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Try using -force  as in:

New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ReceiveTimeout -Value 3000 -Type Dword -Force | Out-Null
Mdamon808Author Commented:
Yup that's done it. Thanks a bunch. As a side note why did I have to add the | out-null part of the line?
Raheman M. AbdulSenior Infrastructure Support Analyst & Systems DeveloperCommented:
Out-Null means discard the output
-Force should have worked in your case.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now