Did you realize that you can Join-Path can work on multiple items?
PS> Get-Help Join-Path -parameter *path-path <string[]> Specifies the main path (or paths) to which the child-path is appended. Wildcards are permitted. The value of Path determines which provider joins the paths and adds th e path delimiters. The Path parameter is required, although the paramet er name (-path) is optional. Required? true Position? 1 Default value N/A - The path must be specified Accept pipeline input? true (ByValue, ByPropertyName) Accept wildcard characters? true-childPath <string> Specifies the elements to append to the value of Path. Wildcards are pe rmitted. The ChildPath parameter is required, although the parameter na me (-ChildPath) is optional. Required? true Position? 2 Default value N/A - The ChildPath must be specified Accept pipeline input? true (ByPropertyName) Accept wildcard characters? True
Let's get crazy!
Notice that PATH accepts an array of STRINGS. This is what that allows you to do:
PS> Join-Path C:\hello worldC:\hello\worldPS> Join-Path C:\hello,d:\goodbye,e:\hola,f:\adios worldC:\hello\worldd:\goodbye\worlde:\hola\worldf:\adios\world
Next, notice that PATH can be pipelined BYVALUE. That allows you to do:
PS> Get-Content t1.txtc:\hellod:\Goodbyee:\holaf:\adiosPS> Get-Content t1.txt | Join-Path -ChildPath worldc:\hello\worldd:\Goodbye\worlde:\hola\worldf:\adios\world
Next, notice that ChildPath can be pipelined BYPROPERTYNAME. That allows you to do:
PS> Get-Content t.csvChildpathWorldJeffreyMicrosoftPS> Import-Csv t.csv |Join-Path c:\helloc:\hello\Worldc:\hello\Jeffreyc:\hello\Microsoftc:\hello\
Next, remember that Path accepts an ARRAY of strings. This allows you to do:
PS> Import-Csv t.csv |Join-Path c:\hello,d:\Good-Byec:\hello\Worldd:\Good-Bye\Worldc:\hello\Jeffreyd:\Good-Bye\Jeffreyc:\hello\Microsoftd:\Good-Bye\Microsoftc:\hello\d:\Good-Bye\
Lastly, notice that both PATH and CHILDPATH can be pipelined BYPROPERTYNAME. That allows you to do:
PS> Get-Content t2.csvPath,Childpathc:\Hello,Worldd:\Good-Bye,Jeffreye:\PowerShell-Rocks,MicrosoftPS> Import-Csv t2.csv |Join-Pathc:\Hello\Worldd:\Good-Bye\Jeffreye:\PowerShell-Rocks\Microsoft
So now what you'll want to do is to a bunch of Get-Help –FULL and example the parameters and look for those that accept arrays of elements and those that accept pipeline input – then experiment.
Enjoy!
Jeffrey Snover [MSFT]Windows Management Partner ArchitectVisit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShellVisit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx