Skip to content

Commit ec1d7f4

Browse files
authored
Update registry examples (#11305)
1 parent ce04493 commit ec1d7f4

File tree

5 files changed

+640
-434
lines changed

5 files changed

+640
-434
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Registry_Provider.md

Lines changed: 128 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Registry
33
Locale: en-US
4-
ms.date: 03/01/2023
4+
ms.date: 07/31/2024
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_registry_provider?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about Registry Provider
@@ -30,43 +30,43 @@ The PowerShell **Registry** provider lets you get, add, change,
3030
clear, and delete registry keys, entries, and values in PowerShell.
3131

3232
The **Registry** drives are a hierarchical namespace containing the registry
33-
keys and subkeys on your computer. Registry entries and values are not
34-
components of that hierarchy. Instead, they are properties of each of the
35-
keys.
36-
37-
The **Registry** provider supports the following cmdlets, which are covered
38-
in this article.
39-
40-
- [Get-Location](xref:Microsoft.PowerShell.Management.Get-Location)
41-
- [Set-Location](xref:Microsoft.PowerShell.Management.Set-Location)
42-
- [Get-Item](xref:Microsoft.PowerShell.Management.Get-Item)
43-
- [Get-ChildItem](xref:Microsoft.PowerShell.Management.Get-ChildItem)
44-
- [Invoke-Item](xref:Microsoft.PowerShell.Management.Invoke-Item)
45-
- [Move-Item](xref:Microsoft.PowerShell.Management.Move-Item)
46-
- [New-Item](xref:Microsoft.PowerShell.Management.New-Item)
47-
- [Remove-Item](xref:Microsoft.PowerShell.Management.Remove-Item)
48-
- [Clear-ItemProperty](xref:Microsoft.PowerShell.Management.Clear-ItemProperty)
49-
- [Get-ItemProperty](xref:Microsoft.PowerShell.Management.Get-ItemProperty)
50-
- [New-ItemProperty](xref:Microsoft.PowerShell.Management.New-ItemProperty)
51-
- [Remove-ItemProperty](xref:Microsoft.PowerShell.Management.Remove-ItemProperty)
52-
- [Set-ItemProperty](xref:Microsoft.PowerShell.Management.Set-ItemProperty)
53-
- [Get-Acl](xref:Microsoft.PowerShell.Security.Get-Acl)
54-
- [Set-Acl](xref:Microsoft.PowerShell.Security.Set-Acl)
33+
keys and subkeys on your computer. Registry entries and values aren't
34+
components of that hierarchy. Instead, they're properties of each of the keys.
35+
36+
The **Registry** provider supports the following cmdlets:
37+
38+
- [Get-Location][13]
39+
- [Set-Location][23]
40+
- [Get-Item][10]
41+
- [Get-ChildItem][09]
42+
- [Invoke-Item][14]
43+
- [Move-Item][15]
44+
- [New-Item][17]
45+
- [Remove-Item][19]
46+
- [Clear-ItemProperty][06]
47+
- [Get-ItemProperty][11]
48+
- [New-ItemProperty][18]
49+
- [Remove-ItemProperty][20]
50+
- [Set-ItemProperty][22]
51+
- [Get-Acl][24]
52+
- [Set-Acl][25]
5553

5654
## Types exposed by this provider
5755

58-
Registry keys are represented as instances of the
59-
[Microsoft.Win32.RegistryKey](/dotnet/api/microsoft.win32.registrykey)
60-
class. Registry entries are represented as instances of the
61-
[PSCustomObject](/dotnet/api/system.management.automation.pscustomobject)
62-
class.
56+
The **Registry** provider returns registry data in one of two types:
57+
58+
- [Microsoft.Win32.RegistryKey][01] for registry keys
59+
- [PSCustomObject][02] for registry values
6360

6461
## Navigating the Registry drives
6562

66-
The **Registry** provider exposes its data store as two default drives. The
67-
registry location HKEY_LOCAL_MACHINE is mapped to the `HKLM:` drive and
68-
HKEY_CURRENT_USER is mapped to the `HKCU:` drive. To work with the registry,
69-
you can change your location to the `HKLM:` drive using the following command.
63+
The **Registry** provider exposes its data store as two default drives.
64+
65+
- `HKLM:` maps to the `HKEY_LOCAL_MACHINE` registry hive
66+
- `HKCU:` maps to the `HKEY_CURRENT_USER` registry hive
67+
68+
To work with the registry, you can change your location to the `HKLM:` drive
69+
using the following command.
7070

7171
```powershell
7272
Set-Location HKLM:
@@ -80,19 +80,18 @@ Set-Location C:
8080

8181
You can also work with the **Registry** provider from any other PowerShell
8282
drive. To reference a registry key from another location, use the drive name
83-
(`HKLM:`, `HKCU:`) in the path. Use a backslash (`\`) or a forward slash (`/`) to
84-
indicate a level of the **Registry** drive.
83+
(`HKLM:`, `HKCU:`) in the path. Use a backslash (`\`) or a forward slash (`/`)
84+
to indicate a level of the **Registry** drive.
8585

8686
```powershell
8787
PS C:\> cd HKLM:\Software
8888
```
8989

9090
> [!NOTE]
9191
> PowerShell uses aliases to allow you a familiar way to work with provider
92-
> paths. Commands such as `dir` and `ls` are now aliases for
93-
> [Get-ChildItem](xref:Microsoft.PowerShell.Management.Get-ChildItem),
94-
> `cd` is an alias for [Set-Location](xref:Microsoft.PowerShell.Management.Set-Location),
95-
> and `pwd` is an alias for [Get-Location](xref:Microsoft.PowerShell.Management.Get-Location).
92+
> paths. Commands such as `dir` and `ls` are aliases for [Get-ChildItem][09],
93+
> `cd` is an alias for [Set-Location][23], and `pwd` is an alias for
94+
> [Get-Location][13].
9695
9796
This last example shows another path syntax you can use to navigate the
9897
**Registry** provider. This syntax uses the provider name, followed by two
@@ -106,16 +105,16 @@ cd "Registry::HKEY_LOCAL_MACHINE\Software"
106105
## Displaying the contents of registry keys
107106

108107
The registry is divided into keys, subkeys, and entries. For more information
109-
about registry structure, see [Structure of the Registry](/windows/desktop/sysinfo/structure-of-the-registry).
108+
about registry structure, see [Structure of the Registry][03].
110109

111110
In a **Registry** drive, each key is a container. A key can contain any number
112111
of keys. A registry key that has a parent key is called a subkey. You can
113112
use `Get-ChildItem` to view registry keys and `Set-Location` to navigate to
114113
a key path.
115114

116115
Registry values are attributes of a registry key. In the **Registry** drive,
117-
they are called **Item Properties**. A registry key can have both children
118-
keys and item properties.
116+
they're called **Item Properties**. A registry key can have both children keys
117+
and item properties.
119118

120119
In this example, the difference between `Get-Item` and `Get-ChildItem` is
121120
shown. When you use `Get-Item` on the "Spooler" registry key, you can view its
@@ -146,9 +145,9 @@ Spooler DependOnService : {RPCSS, http}
146145
```
147146

148147
Each registry key can also have subkeys. When you use `Get-Item` on a registry
149-
key, the subkeys are not displayed. The `Get-ChildItem` cmdlet will show you
150-
children items of the "Spooler" key, including each subkey's properties. The
151-
parent keys properties are not shown when using `Get-ChildItem`.
148+
key, the subkeys aren't displayed. The `Get-ChildItem` cmdlet shows you subkeys
149+
of the "Spooler" key, including each subkey's properties. The parent keys
150+
properties aren't shown when using `Get-ChildItem`.
152151

153152
```powershell
154153
Get-ChildItem -Path HKLM:\SYSTEM\CurrentControlSet\Services\Spooler
@@ -192,8 +191,8 @@ Spooler DependOnService : {RPCSS, http}
192191
For more information on the cmdlets covered in this section, see the following
193192
articles.
194193

195-
-[Get-Item](xref:Microsoft.PowerShell.Management.Get-Item)
196-
-[Get-ChildItem](xref:Microsoft.PowerShell.Management.Get-ChildItem)
194+
-[Get-Item][10]
195+
-[Get-ChildItem][09]
197196

198197
## Viewing registry key values
199198

@@ -262,15 +261,15 @@ Get-ItemPropertyValue -Path HKLM:\SOFTWARE\Microsoft\Wbem -Name BUILD
262261
For more information on the cmdlets used in this section, see the following
263262
articles.
264263

265-
- [Get-ItemProperty](xref:Microsoft.PowerShell.Management.Get-ItemProperty)
266-
- [Get-ItemPropertyValue](xref:Microsoft.PowerShell.Management.Get-ItemProperty)
264+
- [Get-ItemProperty][11]
265+
- [Get-ItemPropertyValue][12]
267266

268267
## Changing registry key values
269268

270-
The `Set-ItemProperty` cmdlet will set attributes for registry keys. The
271-
following example uses `Set-ItemProperty` to change the spooler service start
272-
type to manual. The example changes the **StartType** back to _Automatic_
273-
using the `Set-Service` cmdlet.
269+
The `Set-ItemProperty` cmdlet sets registry values associated with a registry
270+
key. The following example uses `Set-ItemProperty` to change the spooler
271+
service start type to manual. The example changes the **StartType** back to
272+
`Automatic` using the `Set-Service` cmdlet.
274273

275274
```powershell
276275
Get-Service spooler | Select-Object Name, StartMode
@@ -298,7 +297,7 @@ spooler Manual
298297
Set-Service -Name Spooler -StartupType Automatic
299298
```
300299

301-
Each registry key has a _default_ value. You can change the _default_ value
300+
Each registry key has a _default_ value. You can change the `default` value
302301
for a registry key with either `Set-Item` or `Set-ItemProperty`.
303302

304303
```powershell
@@ -309,12 +308,12 @@ Set-Item -Path HKLM:\SOFTWARE\Contoso -Value "two"
309308
For more information on the cmdlets used in this section, see the following
310309
articles.
311310

312-
- [Set-Item](xref:Microsoft.PowerShell.Management.Set-Item)
313-
- [Set-ItemProperty](xref:Microsoft.PowerShell.Management.Set-ItemProperty)
311+
- [Set-Item][21]
312+
- [Set-ItemProperty][22]
314313

315314
## Creating registry keys and values
316315

317-
The `New-Item` cmdlet will create registry keys with a name that you provide.
316+
The `New-Item` cmdlet creates new registry keys with a name that you provide.
318317
You can also use the `mkdir` function, which calls the `New-Item` cmdlet
319318
internally.
320319

@@ -343,18 +342,18 @@ New-ItemProperty -Path $path -Name Test -Type DWORD -Value 1
343342
> Review the dynamic parameters section in this article for other allowed type
344343
> values.
345344
346-
For detailed cmdlet usage, see [New-ItemProperty](xref:Microsoft.PowerShell.Management.New-ItemProperty).
345+
For detailed cmdlet usage, see [New-ItemProperty][18].
347346

348347
## Copying registry keys and values
349348

350349
In the **Registry** provider, use the `Copy-Item` cmdlet copies registry keys
351350
and values. Use the `Copy-ItemProperty` cmdlet to copy registry values only.
352351
The following command copies the "Contoso" registry key, and its properties to
353-
the specified location "HKLM:\Software\Fabrikam".
352+
the specified location `HKLM:\Software\Fabrikam`.
354353

355-
`Copy-Item` creates the destination key if it does not exist. If the
356-
destination key exists, `Copy-Item` creates a duplicate of the source key
357-
as a child item (subkey) of the destination key.
354+
`Copy-Item` creates the destination key if it doesn't exist. If the destination
355+
key exists, `Copy-Item` creates a duplicate of the source key as a child item
356+
(subkey) of the destination key.
358357

359358
```powershell
360359
Copy-Item -Path HKLM:\Software\Contoso -Destination HKLM:\Software\Fabrikam
@@ -372,14 +371,14 @@ Copy-ItemProperty -Path $source -Destination $dest -Name Server
372371
For more information on the cmdlets used in this section, see the following
373372
articles.
374373

375-
- [Copy-Item](xref:Microsoft.PowerShell.Management.Copy-Item)
376-
- [Copy-ItemProperty](xref:Microsoft.PowerShell.Management.Copy-ItemProperty)
374+
- [Copy-Item][07]
375+
- [Copy-ItemProperty][08]
377376

378377
## Moving registry keys and values
379378

380379
The `Move-Item` and `Move-ItemProperty` cmdlets behave like their "Copy"
381380
counterparts. If the destination exists, `Move-Item` moves the source key
382-
underneath the destination key. If the destination key does not exist, the
381+
underneath the destination key. If the destination key doesn't exist, the
383382
source key is moved to the destination path.
384383

385384
The following command moves the "Contoso" key to the path
@@ -389,8 +388,8 @@ The following command moves the "Contoso" key to the path
389388
Move-Item -Path HKLM:\SOFTWARE\Contoso -Destination HKLM:\SOFTWARE\Fabrikam
390389
```
391390

392-
This command moves all of the properties from `HKLM:\SOFTWARE\ContosoCompany`
393-
to `HKLM:\SOFTWARE\Fabrikam`.
391+
This command moves all properties from `HKLM:\SOFTWARE\ContosoCompany` to
392+
`HKLM:\SOFTWARE\Fabrikam`.
394393

395394
```powershell
396395
$source = "HKLM:\SOFTWARE\Contoso"
@@ -401,8 +400,8 @@ Move-ItemProperty -Path $source -Destination $dest -Name *
401400
For more information on the cmdlets used in this section, see the following
402401
articles.
403402

404-
- [Move-Item](xref:Microsoft.PowerShell.Management.Move-Item)
405-
- [Move-ItemProperty](xref:Microsoft.PowerShell.Management.Move-ItemProperty)
403+
- [Move-Item][15]
404+
- [Move-ItemProperty][16]
406405

407406
## Renaming registry keys and values
408407

@@ -432,14 +431,14 @@ $acl | Set-Acl -Path HKLM:\SOFTWARE\Contoso
432431

433432
For more examples and cmdlet usage details see the following articles.
434433

435-
- [Get-Acl](xref:Microsoft.PowerShell.Security.Get-Acl)
436-
- [Set-Acl](xref:Microsoft.PowerShell.Security.Set-Acl)
434+
- [Get-Acl][24]
435+
- [Set-Acl][25]
437436

438437
## Removing and clearing registry keys and values
439438

440-
You can remove contained items by using `Remove-Item`, but you will be
441-
prompted to confirm the removal if the item contains anything else. The
442-
following example attempts to delete a key `HKLM:\SOFTWARE\Contoso`.
439+
You can remove contained items using `Remove-Item`. You are prompted to confirm
440+
the removal if the item contains anything else. The following example attempts
441+
to delete a key `HKLM:\SOFTWARE\Contoso`.
443442

444443
```powershell
445444
dir HKLM:\SOFTWARE\Contoso\
@@ -460,7 +459,7 @@ Remove-Item -Path HKLM:\SOFTWARE\Contoso
460459
```Output
461460
Confirm
462461
The item at HKLM:\SOFTWARE\Contoso has children and the -Recurse
463-
parameter was not specified. If you continue, all children will be removed
462+
parameter wasn't specified. If you continue, all children will be removed
464463
with the item. Are you sure you want to continue?
465464
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
466465
(default is "Y"):
@@ -521,10 +520,10 @@ Contoso
521520

522521
For more examples and cmdlet usage details see the following articles.
523522

524-
- [Clear-Item](xref:Microsoft.PowerShell.Management.Clear-Item)
525-
- [Clear-ItemProperty](xref:Microsoft.PowerShell.Management.Clear-ItemProperty)
526-
- [Remove-Item](xref:Microsoft.PowerShell.Management.Remove-Item)
527-
- [Remove-ItemProperty](xref:Microsoft.PowerShell.Management.Remove-ItemProperty)
523+
- [Clear-Item][05]
524+
- [Clear-ItemProperty][06]
525+
- [Remove-Item][19]
526+
- [Remove-ItemProperty][20]
528527

529528
## Dynamic parameters
530529

@@ -534,32 +533,29 @@ provider-enabled drive.
534533

535534
### Type <Microsoft.Win32.RegistryValueKind>
536535

537-
Establishes or changes the data type of a registry value. The default is `String` (REG_SZ).
538-
539-
This parameter works as designed on the
540-
[Set-ItemProperty](xref:Microsoft.PowerShell.Management.Set-ItemProperty)
541-
cmdlet. It is also available on the
542-
[Set-Item](xref:Microsoft.PowerShell.Management.Set-Item) cmdlet in the
543-
registry drives, but it has no effect.
544-
545-
| Value | Description |
546-
| -------------- | -------------------------------------------------------------- |
547-
| `String` | Specifies a null-terminated string. Used for REG_SZ values. |
548-
| `ExpandString` | Specifies a null-terminated string that contains unexpanded |
549-
| | references to environment variables that are expanded when |
550-
| | the value is retrieved. Used for REG_EXPAND_SZ values. |
551-
| `Binary` | Specifies binary data in any form. Used for REG_BINARY values. |
552-
| `DWord` | Specifies a 32-bit binary number. Used for REG_DWORD values. |
553-
| `MultiString` | Specifies an array of null-terminated strings terminated by |
554-
| | two null characters. Used for REG_MULTI_SZ values. |
555-
| `QWord` | Specifies a 64-bit binary number. Used for REG_QWORD values. |
556-
| `Unknown` | Indicates an unsupported registry data type, such as |
557-
| | REG_RESOURCE_LIST values. |
558-
559-
#### Cmdlets supported
560-
561-
- [Set-Item](xref:Microsoft.PowerShell.Management.Set-Item)
562-
- [Set-ItemProperty](xref:Microsoft.PowerShell.Management.Set-ItemProperty)
536+
Establishes or changes the data type of a registry value. The default is
537+
`String` (REG_SZ).
538+
539+
This parameter works as designed on the [Set-ItemProperty][22] cmdlet. It's
540+
also available on the [Set-Item][21] cmdlet in the registry drives, but it has
541+
no effect.
542+
543+
- `String` - Used for REG_SZ values. Pass a `[System.String]` object to the
544+
**Value** parameter.
545+
- `ExpandString` - Used for REG_EXPAND_SZ values. Pass a `[System.String]`
546+
object to the **Value** parameter. The string should contain unexpanded
547+
references to environment variables that are expanded when the value is
548+
retrieved.
549+
- `Binary` - Used for REG_BINARY values. Pass a `[System.Byte[]]` object to the
550+
**Value** parameter.
551+
- `DWord` - Used for REG_DWORD values. Pass a `[System.Int32]` object to the
552+
**Value** parameter.
553+
- `MultiString` - Used for REG_MULTI_SZ values. Pass a `[System.String[]]`
554+
object to the **Value** parameter.
555+
- `QWord` - Used for REG_QWORD values. Pass a `[System.Int64]` object to the
556+
**Value** parameter.
557+
- `Unknown` - Indicates an unsupported registry data type, such as
558+
REG_RESOURCE_LIST values.
563559

564560
## Using the pipeline
565561

@@ -587,4 +583,31 @@ Get-Help Get-ChildItem -Path HKLM:
587583

588584
## See also
589585

590-
- [about_Providers](about_Providers.md)
586+
- [about_Providers][04]
587+
588+
<!-- link references -->
589+
[01]: /dotnet/api/microsoft.win32.registrykey
590+
[02]: /dotnet/api/system.management.automation.pscustomobject
591+
[03]: /windows/desktop/sysinfo/structure-of-the-registry
592+
[04]: about_Providers.md
593+
[05]: xref:Microsoft.PowerShell.Management.Clear-Item
594+
[06]: xref:Microsoft.PowerShell.Management.Clear-ItemProperty
595+
[07]: xref:Microsoft.PowerShell.Management.Copy-Item
596+
[08]: xref:Microsoft.PowerShell.Management.Copy-ItemProperty
597+
[09]: xref:Microsoft.PowerShell.Management.Get-ChildItem
598+
[10]: xref:Microsoft.PowerShell.Management.Get-Item
599+
[11]: xref:Microsoft.PowerShell.Management.Get-ItemProperty
600+
[12]: xref:Microsoft.PowerShell.Management.Get-ItemPropertyValue
601+
[13]: xref:Microsoft.PowerShell.Management.Get-Location
602+
[14]: xref:Microsoft.PowerShell.Management.Invoke-Item
603+
[15]: xref:Microsoft.PowerShell.Management.Move-Item
604+
[16]: xref:Microsoft.PowerShell.Management.Move-ItemProperty
605+
[17]: xref:Microsoft.PowerShell.Management.New-Item
606+
[18]: xref:Microsoft.PowerShell.Management.New-ItemProperty
607+
[19]: xref:Microsoft.PowerShell.Management.Remove-Item
608+
[20]: xref:Microsoft.PowerShell.Management.Remove-ItemProperty
609+
[21]: xref:Microsoft.PowerShell.Management.Set-Item
610+
[22]: xref:Microsoft.PowerShell.Management.Set-ItemProperty
611+
[23]: xref:Microsoft.PowerShell.Management.Set-Location
612+
[24]: xref:Microsoft.PowerShell.Security.Get-Acl
613+
[25]: xref:Microsoft.PowerShell.Security.Set-Acl

0 commit comments

Comments
 (0)