Path cmdlets: 5 Resolve-Path

I normally start PowerShell in my c:\scripts directory

PS> Get-Location

Path
----
C:\scripts

 

Get-ChildItem *.ps1

gives me the list of .ps1 files in that folder.  Some of that information I may not need and it doesn’t give me the full path

 

PS> Resolve-Path *.ps1

Path
----
C:\scripts\firewall.ps1
C:\scripts\import-mymodule.ps1
C:\scripts\loadaccess.ps1
C:\scripts\route.ps1
C:\scripts\test.ps1
C:\scripts\testf.ps1

 

gives me a list of the files that meet the criteria. The important point is the returned property is called path.  This means we can do this

Resolve-Path *.ps1 | Copy-Item -Destination c:\test –WhatIf

 

In otherwords we can pipe straight into a cmdlet that accepts a Path parameter!

Remember that Get-ChildItem doesn’t produce a property called path.

 

I’ve ignored Resolve-Path up to now but I’m beginning to think of all sorts of uses for it.  The one drawback is that it doesn’t recurse through subfolders

Leave a Reply