You are currently viewing PowerShell Split-Path Cmdlet

PowerShell Split-Path Cmdlet

PowerShell Split-Path Cmdlet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Test-Path cmdlet in PowerShell.

https://cloudaffaire.com/powershell-test-path-cmdlet/

In this blog post, we will discuss Split-Path cmdlet in PowerShell. You can use Split-Path cmdlet to split a path of an item into segments and get the required segment. For example, you Split-Path cmdlet can be used to get a file or directory name from a path. Split-Path cmdlet can also be used to test if a given path is absolute or relative. Split-Path cmdlet can be used in the registry as well.

Split-Path Cmdlet Syntax:

Split-Path Cmdlet Argument List:

  • Credential: To impersonate another user or elevate your credentials.
  • IsAbsolute: Indicates that this cmdlet returns $True if the path is absolute and $False if it is relative.
  • Leaf: Indicates that this cmdlet returns only the last item or container in the path.
  • LiteralPath: Specifies the paths to be split. Unlike Path, the value of LiteralPath is used exactly as it is typed.
  • NoQualifier: Indicates that this cmdlet returns the path without the qualifier.
  • Parent: Indicates that this cmdlet returns only the parent containers of the item or of the container specified by the path.
  • Path: Specifies the paths to be split. Wildcard characters are permitted. If the path includes spaces, enclose it in quotation marks.
  • Qualifier: Indicates that this cmdlet returns only the qualifier of the specified path.
  • Resolve: Indicates that this cmdlet displays the items that are referenced by the resulting split path instead of displaying the path elements.
  • UseTransaction: Includes the command in the active transaction. This parameter is valid only when a transaction is in progress.

PowerShell Split-Path Cmdlet:

Get Only File Or Directory Name From A Path In PowerShell:

Get The Parent Directory Path Of A File Or Directory In PowerShell:

Get The Drive Letter From A File Or Directory Path In PowerShell:

Get The Relative Path Of A File Or Directory In PowerShell:

Check If A Path Of A File Or Directory Is Valid In PowerShell:

Check If A Path Of A File Or Directory Is Absolute Path In PowerShell:

Get Only Registry Key Name From A Path In PowerShell:

Get The Parent Location Of A Registry Key In PowerShell:

Get Root Registry Location Of A Registry Key In PowerShell:

Get Relative Path Of A Registry Key In PowerShell:

Check If A Given Registry Key Path Is Valid In PowerShell:

You Can Also Use Split-Path Cmdlet To Split Path Of A FQDN, though it is not meant to be used with s FQDN.

Hope you have enjoyed this article. In the next blog post, we will discuss Join-Path cmdlet in PowerShell.

To Set more details on PowerShell, kindly follow below official documentation

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-5.1

 

Leave a Reply