# Automate registry entries

**URL:** <https://forums.powershell.org/t/automate-registry-entries/6703>\
**Category:** PowerShell Help\
**Created:** [June 23, 2016, 1:12pm UTC](https://forums.powershell.org/t/automate-registry-entries/6703 "2016-06-23T13:12:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mario-menendez](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mario-menendez](https://forums.powershell.org/u/mario-menendez)\
**Post date:** [June 23, 2016, 1:12pm UTC](https://forums.powershell.org/t/automate-registry-entries/6703/1 "2016-06-23T13:12:07Z")

</div>

Hello,

I am very new to powershell and I am trying to learn and leap into simple things to automate at work. I have a simple batch script that adds values to several registry options. I would like help on automate this batch file with powershell and make it more user interactive. I would like to be able to have user input computer name or username, run the script on any computer on the network. I guess the small the script the better. The batch file is as follow:

reg add “HKEY\_LOCAL\_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System” /v DisableLockWorkstation /t REG\_DWORD /d 1 /f

reg add “HKEY\_CURRENT\_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System” /v DisableLockWorkstation /t REG\_DWORD /d 1 /f

reg add “HKEY\_CURRENT\_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer” /v StarMenuLogOff /t REG\_DWORD /d 1 /f

reg add “HKEY\_LOCAL\_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer” /v StarMenuLogOff /t REG\_DWORD /d 1 /f

reg add “HKEY\_LOCAL\_MACHINE\SOFTWARE \Microsoft\Windows\CurrentVersion\Policies\System” /v HideFastUserSwitching /t REG\_DWORD /d 1 /f

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [June 23, 2016, 1:37pm UTC](https://forums.powershell.org/t/automate-registry-entries/6703/2 "2016-06-23T13:37:19Z")

</div>

Here are two quick examples… first one prompts the user for the target computer name

```
# Get user credentials
$cred = Get-Credential

# Prompt for computer name
$computer = Read-Host -Prompt 'Name of target system'

# Code to execute
$sb = {
    reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableLockWorkstation /t REG_DWORD /d 1 /f

    reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableLockWorkstation /t REG_DWORD /d 1 /f

    reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v StarMenuLogOff /t REG_DWORD /d 1 /f

    reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v StarMenuLogOff /t REG_DWORD /d 1 /f

    reg add "HKEY_LOCAL_MACHINE\SOFTWARE \Microsoft\Windows\CurrentVersion\Policies\System" /v HideFastUserSwitching /t REG_DWORD /d 1 /f
}

# Execute Code
Invoke-Command -ComputerName $computer -Credential $cred -ScriptBlock $sb
```

The second example is almost identical, but instead of promoting the user for the target computer name you provide it as a parameter on script execution.

```
Param ([string]$ComputerName)

# Get user credentials
$cred = Get-Credential

# Code to execute
$sb = {
    reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableLockWorkstation /t REG_DWORD /d 1 /f

    reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System" /v DisableLockWorkstation /t REG_DWORD /d 1 /f

    reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v StarMenuLogOff /t REG_DWORD /d 1 /f

    reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v StarMenuLogOff /t REG_DWORD /d 1 /f

    reg add "HKEY_LOCAL_MACHINE\SOFTWARE \Microsoft\Windows\CurrentVersion\Policies\System" /v HideFastUserSwitching /t REG_DWORD /d 1 /f
}

# Execute Code
Invoke-Command -ComputerName $ComputerName -Credential $cred -ScriptBlock $sb
```

You would execute this like so…

```
PS > .\ScriptName.ps1 -ComputerName Server1
```

Hope that helps.

---

<div class="post-metadata">

**Author:** ![mario-menendez](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@mario-menendez](https://forums.powershell.org/u/mario-menendez)\
**Post date:** [June 28, 2016, 3:11pm UTC](https://forums.powershell.org/t/automate-registry-entries/6703/3 "2016-06-28T15:11:10Z")

</div>

Stefan

Thank you for your help on this, I appreciate it. You rock!!!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:41pm UTC](https://forums.powershell.org/t/automate-registry-entries/6703/4 "2024-05-16T20:41:00Z")

</div>


