question

GlennMaxwell-2309 avatar image
0 Votes"
GlennMaxwell-2309 asked RichMatheisen-8856 commented

adding registry keys using powershell

Hi all
i want to add the below two registry keys on windows servers.
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverrideMask /t REG_DWORD /d 3 /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverride /t REG_DWORD /d 72 /f

i have servers list in text file. i am not sure will the below script work for me.

$ServersList = "C:\servers.txt"
$SS = get-Content -Path $ServersList
foreach ($Servers in $SS ) {
Invoke-Command -ComputerName $Servers -ScriptBlock {
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverrideMask /t REG_DWORD /d 3 /f
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management" /v FeatureSettingsOverride /t REG_DWORD /d 72 /f
}
}

windows-server-powershell
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Looks like it should work. Put one machine name in the file and test it.

0 Votes 0 ·

FWIW, there's no need for the 'foreach' loop. Just use the '$SS' variable as the argument to the -ComputerName parameter in the Invoke-Command cmdlet.

0 Votes 0 ·
GlennMaxwell-2309 avatar image
1 Vote"
GlennMaxwell-2309 answered

it is working i have tested it

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

YoungYang-MSFT avatar image
1 Vote"
YoungYang-MSFT answered

Why not try it?So we will see if it is useful.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thameur-BOURBITA avatar image
1 Vote"
Thameur-BOURBITA answered TANSHUAI commented

Hi,

You can also use a GPO to add or modify a regitry key instead of powershell command.

Don't forget to mark this reply as answer if it help you to fix your issue

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes use a GPO is a better way.

0 Votes 0 ·