<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>My Website &#187; bar</title>
	<atom:link href="http://jansveld.net/powershell/?feed=rss2&#038;tag=bar" rel="self" type="application/rss+xml" />
	<link>http://jansveld.net/powershell</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Wed, 09 Oct 2013 18:31:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.6.1</generator>
		<item>
		<title>Show-Progress: a quick progress bar</title>
		<link>http://jansveld.net/powershell/?p=6</link>
		<comments>http://jansveld.net/powershell/?p=6#comments</comments>
		<pubDate>Mon, 26 May 2008 16:19:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[bar]]></category>
		<category><![CDATA[progress]]></category>

		<guid isPermaLink="false">http://www.jansveld.net/powershell/?p=3</guid>
		<description><![CDATA[Often times I need to run some command on a large set of objects, say a WMI query on a few hundred PCs. Here is a simple script to have an easy way to show a progress bar using the built-in Write-Progress cmdlet. In my PS profile it is aliased as &#8220;bar&#8221; so I can do the following: [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Often times I need to run some command on a large set of objects, say a WMI query on a few hundred PCs. Here is a simple script to have an easy way to show a progress bar using the built-in Write-Progress cmdlet. In my PS profile it is aliased as &#8220;bar&#8221; so I can do the following:</p>
<p style="text-align: left;">Get-Content computers.txt | <strong>bar</strong> |% {Get-WMIObject Win32_ComputerSystem -ComputerName $_} | Export-Csv ComputerInfo.csv</p>
<p>One thing to keep in mind is that the script should be placed early in the pipeline, as it consumes all objects before passing them on in order to count them. This is fine as long as the preceding commands are quick, like getting names from files, AD, SQL etc. It does not matter what kind of objects are passed through the script.</p>
<p>Here is the script (Show-Progress.ps1):</p>
<pre><code><span style="color: #008000;">#</span><span style="color: #008000;"> Store all pipeline objects in an array so we can count them</span><span style="color: #008000;">
</span><span style="color: #800080;">$InputArray</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> @(</span><span style="color: #000080;">$Input</span><span style="color: #000000;">)
</span><span style="color: #008000;">#</span><span style="color: #008000;"> Initialize the counter and length ( divided by 100 so we get the percentage)</span><span style="color: #008000;">
</span><span style="color: #800080;">$counter</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #000000;">1</span><span style="color: #000000;">
</span><span style="color: #800080;">$length</span><span style="color: #000000;"> </span><span style="color: #ff0000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$InputArray</span><span style="color: #000000;">.Length </span><span style="color: #ff0000;">/</span><span style="color: #000000;"> </span><span style="color: #000000;">100</span><span style="color: #000000;">
</span><span style="color: #008000;">#</span><span style="color: #008000;"> Push the objects down the pipeline while updating our progress bar</span><span style="color: #008000;">
</span><span style="color: #800080;">$InputArray</span><span style="color: #000000;"> | </span><span style="font-weight: bold; color: #5f9ea0;">foreach</span><span style="color: #000000;"> {
    </span><span style="font-weight: bold; color: #5f9ea0;">Write-Progress</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">Processing...</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">$_</span><span style="color: #800000;">"</span><span style="color: #000000;"> -perc ([</span><span style="color: #008080;">Int</span><span style="color: #000000;">]</span><span style="color: #800080;">$counter</span><span style="color: #ff0000;">++/</span><span style="color: #800080;">$length</span><span style="color: #000000;">)
    </span><span style="color: #000080;">$_</span><span style="color: #000000;">
}
</span></code></pre>
<p>Enjoy,</p>
<p>Arnoud</p>
]]></content:encoded>
			<wfw:commentRss>http://jansveld.net/powershell/?feed=rss2&#038;p=6</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
