NAME Convert-Path SYNOPSIS Converts a path from a Windows PowerShell path to a Windows PowerShell provider path. Example 1: Convert the working directory to a standard file system path PS C:\>Convert-Path . This command converts the current working directory, which is represented by a dot (.), to a standard file system path. Example 2: Convert a provider path to a standard registry path PS C:\>Convert-Path HKLM:\Software\Microsoft This command converts the Windows PowerShell provider path to a standard registry path. Example 3: Convert a path to a string PS C:\>Convert-Path ~ C:\Users\User01 This command converts the path to the home directory of the current provider, which is the FileSystem provider, to a string. NAME Join-Path SYNOPSIS Combines a path and a child path into a single path. Example 1: Combine a path with a child path PS C:\>Join-Path -Path "C:\win*" -ChildPath "System*" This command uses Join-Path to combine the C:\Win path with the System child path. The Windows PowerShell file system provider, FileSystem joins the path and adds the "\" delimiter. Example 2: Display files and folders by joining a path with a child path PS C:\>Join-Path "C:\win*" "System*" -Resolve This command displays the files and folders that are referenced by joining the C:\Win path and the System child path. It displays the same files and folders as Get-ChildItem, but it displays the fully qualified path to each item. In this command, the Path and ChildPath optional parameter names are omitted. Example 3: Use Join-Path with the Windows PowerShell registry provider PS C:\> PS HKLM:\> Join-Path System *ControlSet* -Resolve This command displays the registry keys in the HKLM\System registry subkey that include ControlSet. The command shows how to use Join-Path with the Windows PowerShell registry provider. Example 4: Combine multiple path roots with a child path PS C:\>Join-Path -Path C:, D:, E:, F: -ChildPath New This command uses Join-Path to combine multiple path roots with a child path. Example 5: Combine the roots of a file system drive with a child path PS C:\>Get-PSDrive -PSProvider filesystem | ForEach {$_.root} | Join-Path -ChildPath "Subdir" This command combines the roots of each Windows PowerShell file system drive in the console with the Subdir child path. The command uses the Get-PSDrive cmdlet to get the Windows PowerShell drives supported by the FileSystem provider. The ForEach-Object statement selects only the Root property of the PSDriveInfo objects and combines it with the sp ecified child path. The output shows that the Windows PowerShell drives on the computer included a drive mapped to the C:\Program Files directory. NAME Resolve-Path SYNOPSIS Resolves the wildcard characters in a path, and displays the path contents. Example 1: Resolve the current path PS C:\>Resolve-Path ~ Path ---- C:\Users\User01 This command resolves the path represented by the tilde character (~), which represents the home path of a file system drive, such as C:. Example 2: Resolve the path of the Windows folder PS C:\>Resolve-Path -Path "windows" Path ---- C:\Windows When run from the root of the C: drive, this command returns the path of the Windows folder in the C: drive. Example 3: Get all paths in the Windows folder PS C:\>"C:\windows\*" | Resolve-Path This command returns all of the folders in the C:\Windows folder. The command uses a pipeline operator (|) to send a path string to Resolve-Path . Example 4: Resolve a UNC path PS C:\>Resolve-Path -Path "\\Server01\public" This command resolves a Universal Naming Convention (UNC) path and returns the shares in the path. Example 5: Get relative paths PS C:\>Resolve-Path -Path "c:\prog*" -Relative ..\Program Files ..\Program Files (x86) ..\programs.txt This command returns relative paths for the directories at the root of the C: drive. Example 6: Resolve a path that contains brackets PS C:\>Resolve-Path -LiteralPath 'test[xml]' This command resolves the path of the Test[xml] subfolder of the current folder. It uses the LiteralPath parameter to indicate that the brackets are not regular expression characters. NAME Split-Path SYNOPSIS Returns the specified part of a path. Example 1: Get the qualifier of a path PS C:\>Split-Path -Path "HKCU:\Software\Microsoft" -Qualifier HKCU: This command returns only the qualifier of the path. The qualifier is the drive. Example 2: Display file names PS C:\>Split-Path -Path "C:\Test\Logs\*.log" -Leaf -Resolve Pass1.log Pass2.log ... This command displays the files that are referenced by the split path. Because this path is split to the last item, also known as the leaf, the command displays only the file names. The Resolve parameter tells Split-Path to display the items that the split path references, instead of displaying the split path. Like all Split-Path commands, this command returns strings. It does not return FileInfo objects that represent the files. Example 3: Get the parent container PS C:\>Split-Path -Path "C:\WINDOWS\system32\WindowsPowerShell\V1.0\about_*.txt" C:\WINDOWS\system32\WindowsPowerShell\V1.0 This command returns only the parent containers of the path. Because it does not include any parameters to specify the split, Split-Path uses the split location default, which is Parent . Example 4: Determines whether a path is absolute PS C:\>Split-Path -Path ".\My Pictures\*.jpg" -IsAbsolute False This command determines whether the path is relative or absolute. In this case, because the path is relative to the current folder, which is represented by a dot (.), it returns $False. Example 5: Change location to a specified path PS C:\>Set-Location (Split-Path -Path $profile) PS C:\Documents and Settings\User01\My Documents\WindowsPowerShell> This command changes your location to the folder that contains the Windows PowerShell profile. The command in parentheses uses Split-Path to return only the parent of the path stored in the built-in $Profile variable. The Parent parameter is the default split location parameter. Therefore, you can omit it from the command. The parentheses direct Windows PowerShell to run the command first. This is a useful way to move to a folder that has a long path name. Example 6: Split a path by using the pipeline PS C:\>'C:\Documents and Settings\User01\My Documents\My Pictures' | Split-Path C:\Documents and Settings\User01\My Documents This command uses a pipeline operator (|) to send a path to Split-Path . The path is enclosed in quotation marks to indicate that it is a single token. NAME Test-Path SYNOPSIS Determines whether all elements of a file or directory path exist. -------------------------- EXAMPLE 1 -------------------------- C:\PS>Test-Path -Path "C:\Documents and Settings\NicoleH" Description ----------- This command tells whether all elements in the path exist, that is, the C: directory, the Documents and Settings directory, and the NicoleH directory. If any are missing, the cmdlet returns FALSE. Otherwise, it returns TRUE. -------------------------- EXAMPLE 2 -------------------------- C:\PS>Test-Path -Path $profile C:\PS>Test-Path -Path $profile -IsValid Description ----------- These commands test the path to the Windows PowerShell profile. The first command determines whether all elements in the path exist. The second command determines whether the syntax of the path is correct. In this case, the path is FALSE, but the syntax is correct (TRUE). These commands use $ profile, the automatic variable that points to the location for the profile, even if the profile does not exist. For more information about automatic variables, see about_Automatic_Variables. -------------------------- EXAMPLE 3 -------------------------- C:\PS>Test-Path -Path "C:\CAD\Commercial Buildings\*" -Exclude *.dwg Description ----------- This command tells whether there are any files in the Commercial Buildings directory other than .dwg files. The command uses the Path parameter to specify the path. Because it includes a space, the path is enclosed in quotes. The asterisk at the end of the path indicates the contents of the Commercial Building directory. (With long pat hs, like this one, type the first few letters of the path, and then use the TAB key to complete the path.) The command uses the Exclude parameter to specify files that will be omitted from the evaluation. In this case, because the directory contains only .dwg files, the result is FALSE. -------------------------- EXAMPLE 4 -------------------------- C:\PS>Test-Path -Path $profile -PathType Leaf Description ----------- This command tells whether the path stored in the $profile variable leads to a file. In this case, because the Windows PowerShell profile is a .ps1 file, the cmdlet returns TRUE. -------------------------- EXAMPLE 5 -------------------------- C:\PS>Test-Path -Path HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell TRUE C:\PS> Test-Path -Path HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ExecutionPolicy FALSE Description ----------- These commands use the Test-Path cmdlet with the Windows PowerShell registry provider. The first command tests whether the registry path to the Microsoft.PowerShell registry key is correct on the system. If Windows PowerShell is installed correctly, the cmdlet returns TRUE. Test-Path does not work correctly with all Windows PowerShell providers. For example, you can use Test-Path to test the path to a registry key, but if you use it to test the path to a registry entry, it always returns FALSE, even if the registry entry is present. -------------------------- EXAMPLE 6 -------------------------- C:\PS>Test-Path $pshome\PowerShell.exe -NewerThan "July 13, 2009" Description ----------- This command uses the NewerThan dynamic parameter to determine whether the PowerShell.exe file on the computer is newer than July 13, 2009. The NewerThan parameter works only in file system drives.