0

我对制作 PowerShell 脚本很陌生。我从我的公司得到了一项任务,即从 .ps1 文件中设置所有注册表项。我发现了一个函数,它只设置 1 个注册表项,但不是全部都在 .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

4

1 回答 1

0

如果您的环境允许使用注册表编辑工具,您可以这样做

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。您的用户是否有权访问这些密钥?如果没有,您应该将它们注释掉或一起删除它们

于 2020-05-27T12:39:36.410 回答