Установите все ключи реестра с помощью одной функции PowerShell - PullRequest
0 голосов
/ 27 мая 2020

Я новичок в создании сценариев PowerShell. Я получил задание от своей компании установить все ключи реестра из файла .ps1. Я нашел функцию, которая устанавливает только одну запись реестра, но не все из них внутри файла .ps1.

Найденная мною функция: https://www.powershellgallery.com/packages/Carbon/2.3.0/Content/Functions%5CSet-RegistryKeyValue.ps1

Проблема с этой функцией в том, что она устанавливает только одну клавишу за раз, когда я ее вызываю. Есть ли другой способ решить эту проблему, или мне нужно использовать это решение, даже если мне придется вызывать эту функцию 33 раза.


Это мои записи реестра, которые необходимо установить / установить:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\clechasseur\PathCopyCopy]
"LastUpdateCheck"=hex(b):2f,dd,6f,5c,00,00,00,00
"SettingsFormPosX"=dword:000003c3
"SettingsFormPosY"=dword:000001ac
"MainMenuDisplayOrder"="{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28}"
"SubmenuDisplayOrder"="{3a42b5c6-72d6-4a8a-ba44-014fa64aa11a},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{331a3b60-af49-44f4-b30d-56adff6d25e8},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{8f2adccc-9693-407d-9300-fccb9a12b982},{7da6a4a2-ae54-40e0-9910-ebd9ef3f017e}"
"UIDisplayOrder"="{c8757dca-1ba8-48d0-8145-b93bbb9237af},{3a42b5c6-72d6-4a8a-ba44-014fa64aa11a},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{93b362d1-2b13-467a-b618-6784f24f3ba1},{331a3b60-af49-44f4-b30d-56adff6d25e8},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{0929538b-5f52-4480-9902-2bbec9c84905},{349939d7-780f-43fd-a98e-83d9add44e22},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{891f9e3e-0b70-49fd-a86c-53b21c6193c7},{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{73188fb3-8e14-409c-95ef-ba608fdc1274},{e2c942ac-917c-4aee-a867-8f6ab960ba76},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{8f2adccc-9693-407d-9300-fccb9a12b982},{7da6a4a2-ae54-40e0-9910-ebd9ef3f017e},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{5b5da5cb-3284-45a9-a1e5-4d6b03107924},{cd50dce3-9a5c-4adf-b552-1741361567d6},{bd574871-5df9-4b64-83d1-2af9c0c17f66}"
"KnownPlugins"="{0929538b-5f52-4480-9902-2bbec9c84905},{331a3b60-af49-44f4-b30d-56adff6d25e8},{349939d7-780f-43fd-a98e-83d9add44e22},{3a42b5c6-72d6-4a8a-ba44-014fa64aa11a},{5b5da5cb-3284-45a9-a1e5-4d6b03107924},{73188fb3-8e14-409c-95ef-ba608fdc1274},{7da6a4a2-ae54-40e0-9910-ebd9ef3f017e},{891f9e3e-0b70-49fd-a86c-53b21c6193c7},{8f2adccc-9693-407d-9300-fccb9a12b982},{93b362d1-2b13-467a-b618-6784f24f3ba1},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{bd574871-5df9-4b64-83d1-2af9c0c17f66},{c8757dca-1ba8-48d0-8145-b93bbb9237af},{cd50dce3-9a5c-4adf-b552-1741361567d6},{e2c942ac-917c-4aee-a867-8f6ab960ba76},{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28}"
"AddQuotes"=dword:00000001
"AreQuotesOptional"=dword:00000001
"UseFQDN"=dword:00000001
"DisableSoftwareUpdate"=dword:00000001
"SettingsFormSizeWidth"=dword:00000201
"SettingsFormSizeHeight"=dword:0000027e
"AlwaysShowSubmenu"=dword:00000001
"UseIconForSubmenu"=dword:00000001
"DropRedundantWords"=dword:00000001
"UsePreviewMode"=dword:00000000
 
[HKEY_CURRENT_USER\Software\clechasseur\PathCopyCopy\Icons]
 
[HKEY_CURRENT_USER\Software\clechasseur\PathCopyCopy\PipelinePlugins]
"DisplayOrder"=""
 
[HKEY_CURRENT_USER\Software\clechasseur\PathCopyCopy\Plugins]
 
[HKEY_CURRENT_USER\Software\clechasseur\PathCopyCopy\Rundll32Output]
 
[HKEY_CURRENT_USER\Software\clechasseur\PathCopyCopy\TempPipelinePlugins]

[HKEY_LOCAL_MACHINE\Software\clechasseur\PathCopyCopy]
"LastUpdateCheck"=hex(b):2f,dd,6f,5c,00,00,00,00
"SettingsFormPosX"=dword:000003c3
"SettingsFormPosY"=dword:000001ac
"MainMenuDisplayOrder"="{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28}"
"SubmenuDisplayOrder"="{3a42b5c6-72d6-4a8a-ba44-014fa64aa11a},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{331a3b60-af49-44f4-b30d-56adff6d25e8},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{8f2adccc-9693-407d-9300-fccb9a12b982},{7da6a4a2-ae54-40e0-9910-ebd9ef3f017e}"
"UIDisplayOrder"="{c8757dca-1ba8-48d0-8145-b93bbb9237af},{3a42b5c6-72d6-4a8a-ba44-014fa64aa11a},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{93b362d1-2b13-467a-b618-6784f24f3ba1},{331a3b60-af49-44f4-b30d-56adff6d25e8},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{0929538b-5f52-4480-9902-2bbec9c84905},{349939d7-780f-43fd-a98e-83d9add44e22},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{891f9e3e-0b70-49fd-a86c-53b21c6193c7},{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{73188fb3-8e14-409c-95ef-ba608fdc1274},{e2c942ac-917c-4aee-a867-8f6ab960ba76},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{8f2adccc-9693-407d-9300-fccb9a12b982},{7da6a4a2-ae54-40e0-9910-ebd9ef3f017e},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{5b5da5cb-3284-45a9-a1e5-4d6b03107924},{cd50dce3-9a5c-4adf-b552-1741361567d6},{bd574871-5df9-4b64-83d1-2af9c0c17f66}"
"KnownPlugins"="{0929538b-5f52-4480-9902-2bbec9c84905},{331a3b60-af49-44f4-b30d-56adff6d25e8},{349939d7-780f-43fd-a98e-83d9add44e22},{3a42b5c6-72d6-4a8a-ba44-014fa64aa11a},{5b5da5cb-3284-45a9-a1e5-4d6b03107924},{73188fb3-8e14-409c-95ef-ba608fdc1274},{7da6a4a2-ae54-40e0-9910-ebd9ef3f017e},{891f9e3e-0b70-49fd-a86c-53b21c6193c7},{8f2adccc-9693-407d-9300-fccb9a12b982},{93b362d1-2b13-467a-b618-6784f24f3ba1},{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3},{bd574871-5df9-4b64-83d1-2af9c0c17f66},{c8757dca-1ba8-48d0-8145-b93bbb9237af},{cd50dce3-9a5c-4adf-b552-1741361567d6},{e2c942ac-917c-4aee-a867-8f6ab960ba76},{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28}"
"AddQuotes"=dword:00000001
"AreQuotesOptional"=dword:00000001
"UseFQDN"=dword:00000001
"DisableSoftwareUpdate"=dword:00000001
"SettingsFormSizeWidth"=dword:00000201
"SettingsFormSizeHeight"=dword:0000027e
"AlwaysShowSubmenu"=dword:00000001
"UseIconForSubmenu"=dword:00000001
"DropRedundantWords"=dword:00000001
"UsePreviewMode"=dword:00000000
 
[HKEY_LOCAL_MACHINE\Software\clechasseur\PathCopyCopy\Icons]
 
[HKEY_LOCAL_MACHINE\Software\clechasseur\PathCopyCopy\PipelinePlugins]
"DisplayOrder"=""
 
[HKEY_LOCAL_MACHINE\Software\clechasseur\PathCopyCopy\Plugins]
 
[HKEY_LOCAL_MACHINE\Software\clechasseur\PathCopyCopy\Rundll32Output]
 
[HKEY_LOCAL_MACHINE\Software\clechasseur\PathCopyCopy\TempPipelinePlugins]

Я надеюсь, что кто-нибудь умеет создавать сценарии PowerShell. Я был бы очень признателен, если бы кто-нибудь помог мне с моей проблемой!

С уважением, II

1 Ответ

0 голосов
/ 27 мая 2020

Если ваша среда позволяет использовать инструменты редактирования реестра, вы можете сделать

regedit /s "path\to\pathcopycopy.reg"

Или, если это не разрешено, вы можете создать сценарий, который устанавливает все эти значения, переводя файл реестра записи в код PowerShell:

Set-StrictMode -Version Latest

# create variables for repeating long string values
$MainMenuDisplayOrder = '{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28}'

$SubMenuDisplayOrder = '{3a42b5c6-72d6-4a8a-ba44-014fa64aa11a}','{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}','{331a3b60-af49-44f4-b30d-56adff6d25e8}',
                       '{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}','{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28}','{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}',
                       '{8f2adccc-9693-407d-9300-fccb9a12b982}','{7da6a4a2-ae54-40e0-9910-ebd9ef3f017e}' -join ','

$UIDisplayOrder = '{c8757dca-1ba8-48d0-8145-b93bbb9237af}','{3a42b5c6-72d6-4a8a-ba44-014fa64aa11a}','{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}',
                  '{93b362d1-2b13-467a-b618-6784f24f3ba1}','{331a3b60-af49-44f4-b30d-56adff6d25e8}','{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}',
                  '{0929538b-5f52-4480-9902-2bbec9c84905}','{349939d7-780f-43fd-a98e-83d9add44e22}','{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}',
                  '{891f9e3e-0b70-49fd-a86c-53b21c6193c7}','{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28}','{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}',
                  '{73188fb3-8e14-409c-95ef-ba608fdc1274}','{e2c942ac-917c-4aee-a867-8f6ab960ba76}','{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}',
                  '{8f2adccc-9693-407d-9300-fccb9a12b982}','{7da6a4a2-ae54-40e0-9910-ebd9ef3f017e}','{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}',
                  '{5b5da5cb-3284-45a9-a1e5-4d6b03107924}','{cd50dce3-9a5c-4adf-b552-1741361567d6}','{bd574871-5df9-4b64-83d1-2af9c0c17f66}' -join ','

$KnownPlugins = '{0929538b-5f52-4480-9902-2bbec9c84905}','{331a3b60-af49-44f4-b30d-56adff6d25e8}','{349939d7-780f-43fd-a98e-83d9add44e22}',
                '{3a42b5c6-72d6-4a8a-ba44-014fa64aa11a}','{5b5da5cb-3284-45a9-a1e5-4d6b03107924}','{73188fb3-8e14-409c-95ef-ba608fdc1274}',
                '{7da6a4a2-ae54-40e0-9910-ebd9ef3f017e}','{891f9e3e-0b70-49fd-a86c-53b21c6193c7}','{8f2adccc-9693-407d-9300-fccb9a12b982}',
                '{93b362d1-2b13-467a-b618-6784f24f3ba1}','{afa4d1e1-ba73-4330-a6ab-e574ff39ecc3}','{bd574871-5df9-4b64-83d1-2af9c0c17f66}',
                '{c8757dca-1ba8-48d0-8145-b93bbb9237af}','{cd50dce3-9a5c-4adf-b552-1741361567d6}','{e2c942ac-917c-4aee-a867-8f6ab960ba76}',
                '{ea24bcc3-35f5-46b9-a2a5-a12a0aed2d28}' -join ','

$regPath = 'HKCU:\Software\clechasseur\PathCopyCopy'
if (!(Test-Path -LiteralPath $regPath)) { New-Item -Path $regPath -Force }
$null = New-ItemProperty -LiteralPath $regPath -Name 'LastUpdateCheck' -Value 1550834991 -PropertyType QWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SettingsFormPosX' -Value 963 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SettingsFormPosY' -Value 428 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'MainMenuDisplayOrder' -Value $MainMenuDisplayOrder -PropertyType String -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SubmenuDisplayOrder' -Value $SubMenuDisplayOrder -PropertyType String -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'UIDisplayOrder' -Value $UIDisplayOrder -PropertyType String -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'KnownPlugins' -Value $KnownPlugins -PropertyType String -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'AddQuotes' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'AreQuotesOptional' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'UseFQDN' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'DisableSoftwareUpdate' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SettingsFormSizeWidth' -Value 513 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SettingsFormSizeHeight' -Value 638 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'AlwaysShowSubmenu' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'UseIconForSubmenu' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'DropRedundantWords' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'UsePreviewMode' -Value 0 -PropertyType DWord -Force

$regPath = 'HKCU:\Software\clechasseur\PathCopyCopy\Icons'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }

$regPath = 'HKCU:\Software\clechasseur\PathCopyCopy\PipelinePlugins'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }
$null = New-ItemProperty -LiteralPath $regPath -Name 'DisplayOrder' -Value '' -PropertyType String -Force

$regPath = 'HKCU:\Software\clechasseur\PathCopyCopy\Plugins'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }

$regPath = 'HKCU:\Software\clechasseur\PathCopyCopy\Rundll32Output'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }

$regPath = 'HKCU:\Software\clechasseur\PathCopyCopy\TempPipelinePlugins'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }

$regPath = 'HKLM:\Software\clechasseur\PathCopyCopy'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }
$null = New-ItemProperty -LiteralPath $regPath -Name 'LastUpdateCheck' -Value 1550834991 -PropertyType QWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SettingsFormPosX' -Value 963 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SettingsFormPosY' -Value 428 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'MainMenuDisplayOrder' -Value $MainMenuDisplayOrder -PropertyType String -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SubmenuDisplayOrder' -Value $SubMenuDisplayOrder -PropertyType String -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'UIDisplayOrder' -Value $UIDisplayOrder -PropertyType String -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'KnownPlugins' -Value $KnownPlugins -PropertyType String -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'AddQuotes' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'AreQuotesOptional' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'UseFQDN' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'DisableSoftwareUpdate' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SettingsFormSizeWidth' -Value 513 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'SettingsFormSizeHeight' -Value 638 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'AlwaysShowSubmenu' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'UseIconForSubmenu' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'DropRedundantWords' -Value 1 -PropertyType DWord -Force
$null = New-ItemProperty -LiteralPath $regPath -Name 'UsePreviewMode' -Value 0 -PropertyType DWord -Force

$regPath = 'HKLM:\Software\clechasseur\PathCopyCopy\Icons'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }

$regPath = 'HKLM:\Software\clechasseur\PathCopyCopy\PipelinePlugins'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }
$null = New-ItemProperty -LiteralPath $regPath -Name 'DisplayOrder' -Value '' -PropertyType String -Force

$regPath = 'HKLM:\Software\clechasseur\PathCopyCopy\Plugins'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }

$regPath = 'HKLM:\Software\clechasseur\PathCopyCopy\Rundll32Output'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }

$regPath = 'HKLM:\Software\clechasseur\PathCopyCopy\TempPipelinePlugins'
if (!(Test-Path -LiteralPath $regPath)) { $null = New-Item -Path $regPath -Force }

PS Параметры, которые необходимо установить, также включают параметры в HKEY_LOCAL_MACHINE. Есть ли у ваших пользователей разрешение на доступ к этим ключам? Если нет, закомментируйте их или удалите их полностью

...