Items
Support for each of the *-Item commands varies from one provider to another. The filesystem provider supports all the commands, while the Registry provider supports a smaller number.
Testing for existing items
The Test-Path command may be used to test for the existence of a specific item under a drive:
Test-Path HKLM:\Software\Publisher
Test-Path distinguishes between item types with the PathType parameter. The container and leaf terms are used across providers to broadly classify items.
The following commands test for items of differing types:
Test-Path C:\Windows -PathType Container
Test-Path C:\Windows\System32\cmd.exe -PathType Leaf
Conversely, testing a path that is a file (leaf) with the container PathType will return false:
Test-Path C:\Windows\System32\cmd.exe -PathType Container
The Test-Path command is often used in an if statement prior to creating a file or directory to determine if creating the object is necessary:
if...