<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Expanding Wildcards in PowerShell</title>
	<atom:link href="http://www.owenpellegrin.com/blog/powershell/expanding-wildcards-in-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.owenpellegrin.com/blog/powershell/expanding-wildcards-in-powershell/</link>
	<description>I write stuff here</description>
	<lastBuildDate>Mon, 30 Jan 2012 02:39:32 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
	<item>
		<title>By: Powershell wildcards &#124; Hyfresh</title>
		<link>http://www.owenpellegrin.com/blog/powershell/expanding-wildcards-in-powershell/comment-page-1/#comment-32252</link>
		<dc:creator>Powershell wildcards &#124; Hyfresh</dc:creator>
		<pubDate>Fri, 04 Nov 2011 09:07:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.atmaweapon.org/blog/?p=29#comment-32252</guid>
		<description>[...] Expanding Wildcards in PowerShell &#124; Yeah it&#8217;s a blogExpanding Wildcards in PowerShell. Posted on July 22, 2008 by Owen Pellegrin. Yesterday I thought I&#8217;d jump into the deep end of PowerShell and try to make a &#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] Expanding Wildcards in PowerShell | Yeah it&#8217;s a blogExpanding Wildcards in PowerShell. Posted on July 22, 2008 by Owen Pellegrin. Yesterday I thought I&#8217;d jump into the deep end of PowerShell and try to make a &#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SteveSw</title>
		<link>http://www.owenpellegrin.com/blog/powershell/expanding-wildcards-in-powershell/comment-page-1/#comment-21241</link>
		<dc:creator>SteveSw</dc:creator>
		<pubDate>Sun, 29 May 2011 20:15:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.atmaweapon.org/blog/?p=29#comment-21241</guid>
		<description>I came across this several years after the fact, trying to figure out how to expand a parameter passed to a function with wild cards in it.

This code seems to work: passed a single string $pattern, it will fill a character array $files with all the files that match the pattern in the current directory:

function expand-arg
{
[CmdletBinding()]
param([string] $pattern)
    $loc = Get-Location
    $provider = $loc.Provider    
    $files = @()
    $longfiles = $pscmdlet.GetResolvedProviderPathFromPSPath($pattern, [ref] $provider)
    $longfiles &#124; % { $file = gci $_ ; $files += $file.Name }

#  your logic here
}

There are several things here that weren&#039;t entirely obvious to me. First, I used the CmdletBinding() attribute so that I could get at a pscmdlet instance (which implements the GetResolvedProviderPathFromPSPath() method). Second, I fished a ProviderInfo instance out of the current location (this should work inside any provider) -- you need one of those to pass as the second argument of GetResolvedProviderPathFromPSPath()). And then third, I used gci to strip the filename off the complete names returned to me by GetResolvedProviderPathFromPSPath(), and to discard the current directory (which is inexplicably returned by GetResolvedProviderPathFromPSPath() even when it doesn&#039;t match the wildcards in the pattern).</description>
		<content:encoded><![CDATA[<p>I came across this several years after the fact, trying to figure out how to expand a parameter passed to a function with wild cards in it.</p>
<p>This code seems to work: passed a single string $pattern, it will fill a character array $files with all the files that match the pattern in the current directory:</p>
<p>function expand-arg<br />
{<br />
[CmdletBinding()]<br />
param([string] $pattern)<br />
    $loc = Get-Location<br />
    $provider = $loc.Provider<br />
    $files = @()<br />
    $longfiles = $pscmdlet.GetResolvedProviderPathFromPSPath($pattern, [ref] $provider)<br />
    $longfiles | % { $file = gci $_ ; $files += $file.Name }</p>
<p>#  your logic here<br />
}</p>
<p>There are several things here that weren&#8217;t entirely obvious to me. First, I used the CmdletBinding() attribute so that I could get at a pscmdlet instance (which implements the GetResolvedProviderPathFromPSPath() method). Second, I fished a ProviderInfo instance out of the current location (this should work inside any provider) &#8212; you need one of those to pass as the second argument of GetResolvedProviderPathFromPSPath()). And then third, I used gci to strip the filename off the complete names returned to me by GetResolvedProviderPathFromPSPath(), and to discard the current directory (which is inexplicably returned by GetResolvedProviderPathFromPSPath() even when it doesn&#8217;t match the wildcards in the pattern).</p>
]]></content:encoded>
	</item>
</channel>
</rss>

