<?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>Andy Oakley &#187; Powershell</title>
	<atom:link href="http://andyoakley.com/category/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://andyoakley.com</link>
	<description></description>
	<lastBuildDate>Sat, 28 Aug 2010 21:58:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
	<atom:link rel='hub' href='http://andyoakley.com/?pushpress=hub'/>
		<item>
		<title>More PivotTables in PowerShell</title>
		<link>http://andyoakley.com/2009/12/21/more-pivottables-in-powershell/</link>
		<comments>http://andyoakley.com/2009/12/21/more-pivottables-in-powershell/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 02:38:45 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[hierarchy]]></category>
		<category><![CDATA[pivot]]></category>
		<category><![CDATA[pivottable]]></category>

		<guid isPermaLink="false">http://andyoakley.com/?p=1263</guid>
		<description><![CDATA[Similar to the Simple PivotTables in Excel script I wrote a while back, today I needed to do a different type of pivot by hierarchy. I had a flat table of rows which I wanted to group by several columns recursively. # Given data such as # # A B C # ------- ----------- ---- [...]]]></description>
			<content:encoded><![CDATA[<p>Similar to the <a href="http://andyoakley.com/2009/10/31/simple-pivottables-in-powershell/">Simple PivotTables in Excel</a> script I wrote a while back, today I needed to do a different type of pivot by hierarchy. I had a flat table of rows which I wanted to group by several columns recursively.</p>
<pre class="brush: powershell;">
# Given data such as
#
# A       B           C
# ------- ----------- ----
# red     lisbon      cat
# blue    venice      dog
# green   paris       cat
# blue    london      dog
# green   lisbon      fish
# green   paris       cat
#
# Output the following
#
#  cat
#     red
#         lisbon           1
#     green
#         paris            2
#  dog
#     blue
#         venice           1
#         london           1
#  fish
#     green
#         lisbon           1
#
# $list | output-hierarchy &amp;quot;C&amp;quot;,&amp;quot;A&amp;quot;,&amp;quot;B&amp;quot;

function output-hierarchy
{
    param($hierarchy,$depth=0)
    if ($depth -gt 5) { return }

    $groups = $input | group $hierarchy[0]
    foreach ($group in $groups)
    {
        if ($hierarchy.length -gt 1)
        {
            # Emit title at this level
            &amp;quot;`t&amp;quot;*$depth + $group.name

            $group.group | output-hierarchy $hierarchy[1..($hierarchy.length-1)] ($depth+1)
        }
        else
        {
            # Figure out how many spaces to right align count
            $spacer=(60-$group.name.length-$depth-$group.group.count.tostring().length)

            # End of the road, count the remaining items that fall into this category
            &amp;quot;`t&amp;quot;*$depth + $group.name + &amp;quot; &amp;quot;*$spacer + $group.group.count
        }
    }
}
</pre>
<p><small>Originally posted to <a href="http://andyoakley.com">Andy Oakley.com</a> |
<a href="http://andyoakley.com/2009/12/21/more-pivottables-in-powershell/">Permalink</a> | Categories: <a href="http://andyoakley.com/category/powershell/" title="View all posts in Powershell" rel="category tag">Powershell</a> | Tags: <a href="http://andyoakley.com/tag/hierarchy/" rel="tag">hierarchy</a>, <a href="http://andyoakley.com/tag/pivot/" rel="tag">pivot</a>, <a href="http://andyoakley.com/tag/pivottable/" rel="tag">pivottable</a>, <a href="http://andyoakley.com/tag/powershell/" rel="tag">Powershell</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://andyoakley.com/2009/12/21/more-pivottables-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple PivotTables in PowerShell</title>
		<link>http://andyoakley.com/2009/10/31/simple-pivottables-in-powershell/</link>
		<comments>http://andyoakley.com/2009/10/31/simple-pivottables-in-powershell/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 00:51:17 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[pivot]]></category>
		<category><![CDATA[pivottable]]></category>

		<guid isPermaLink="false">http://andyoakley.com/?p=1140</guid>
		<description><![CDATA[Quick script for PivotTable-like functionality in PowerShell. I find myself using this a lot. # Rotates a vertical set similar to an Excel PivotTable # # Given $data in the format: # # Category Activity Duration # ------------ ------------ -------- # Management Email 1 # Management Slides 4 # Project A Email 2 # Project [...]]]></description>
			<content:encoded><![CDATA[<p>Quick script for PivotTable-like functionality in PowerShell. I find myself using this a lot.</p>
<pre class="brush: powershell;">
# Rotates a vertical set similar to an Excel PivotTable
#
# Given $data in the format:
#
# Category     Activity     Duration
# ------------ ------------ --------
# Management   Email               1
# Management   Slides              4
# Project A    Email               2
# Project A    Research            1
# Project B    Research            3
#
# with $keep = &amp;quot;Category&amp;quot;, $rotate = &amp;quot;Activity&amp;quot;, $value = &amp;quot;Duration&amp;quot;
#
# Return
#
# Category   Email Slides Research
# ---------- ----- ------ --------
# Management     1      4
# Project A      2               1
# Project B                      3

$rotate = &amp;quot;Activity&amp;quot;
$keep = &amp;quot;Category&amp;quot;
$value = &amp;quot;Duration&amp;quot;

$pivots = $data | select -unique $rotate | foreach { $_.Activity}

$data |
	group $keep |
	foreach {
		$group = $_.Group
		$row = new-object psobject
		$row | add-member NoteProperty $keep $_.Name
		foreach ($pivot in $pivots) { $row | add-member NoteProperty $pivot ($group | where { $_.$rotate -eq $pivot } | measure -sum $value).Sum }
		$row
	}
</pre>
<p><small>Originally posted to <a href="http://andyoakley.com">Andy Oakley.com</a> |
<a href="http://andyoakley.com/2009/10/31/simple-pivottables-in-powershell/">Permalink</a> | Categories: <a href="http://andyoakley.com/category/powershell/" title="View all posts in Powershell" rel="category tag">Powershell</a>, <a href="http://andyoakley.com/category/technology/" title="View all posts in Technology" rel="category tag">Technology</a> | Tags: <a href="http://andyoakley.com/tag/excel/" rel="tag">excel</a>, <a href="http://andyoakley.com/tag/pivot/" rel="tag">pivot</a>, <a href="http://andyoakley.com/tag/pivottable/" rel="tag">pivottable</a>, <a href="http://andyoakley.com/tag/powershell/" rel="tag">Powershell</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://andyoakley.com/2009/10/31/simple-pivottables-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell to Twitter</title>
		<link>http://andyoakley.com/2008/09/01/powershell-to-twitter/</link>
		<comments>http://andyoakley.com/2008/09/01/powershell-to-twitter/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 17:14:47 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://apoakley.wordpress.com/?p=612</guid>
		<description><![CDATA[I have too much time on my hands this morning. The following script makes it easy to get and set Twitter status. I&#8217;ve seen similar ones elsewhere but they all seemed to have external dependencies, this one does not. #twitter.ps1: $script:username = &#38;quot;foo&#38;quot; $script:password = &#38;quot;bar&#38;quot; function get-twitter {  $wc = new-object System.Net.Webclient  $wc.Credentials = [...]]]></description>
			<content:encoded><![CDATA[<p>I have too much time on my hands this morning. The following script makes it easy to get and set Twitter status. I&#8217;ve seen similar ones elsewhere but they all seemed to have external dependencies, this one does not.</p>
<pre class="brush: powershell;">
#twitter.ps1:
$script:username = &amp;quot;foo&amp;quot;
$script:password = &amp;quot;bar&amp;quot;
function get-twitter
{
 $wc = new-object System.Net.Webclient
 $wc.Credentials = new-object System.Net.NetworkCredential $script:username,$script:password 
 $rest = $wc.DownloadString(&amp;quot;&amp;lt;a href=&amp;quot;http://twitter.com/statuses/friends_timeline.xml&amp;quot;&amp;gt;http://twitter.com/statuses/friends_timeline.xml&amp;lt;/a&amp;gt;&amp;quot;)
 $xml = [xml]$rest
 $xml.statuses.status
}
function set-twitter
{
 param($status)
 $wc = new-object System.Net.Webclient
 $wc.Credentials = new-object System.Net.NetworkCredential $script:username,$script:password 
 [System.Reflection.Assembly]::LoadWithPartialName(&amp;quot;System.Web&amp;quot;) | out-null
 $encodedstatus = [System.Web.HttpUtility]::UrlEncode($status)
 $postdata = &amp;quot;status=$encodedstatus&amp;quot;
 $postbytes = [System.Text.Encoding]::ASCII.GetBytes($postdata)
 $wc.Headers.Add(&amp;quot;Content-Type&amp;quot;, &amp;quot;application/x-www-form-urlencoded&amp;quot;)
 [System.Text.Encoding]::ASCII.GetString($wc.UploadData(&amp;quot;&amp;lt;a href=&amp;quot;http://twitter.com/statuses/update.xml&amp;quot;&amp;gt;http://twitter.com/statuses/update.xml&amp;lt;/a&amp;gt;&amp;quot;, $postbytes))
}
</pre>
<p><small>Originally posted to <a href="http://andyoakley.com">Andy Oakley.com</a> |
<a href="http://andyoakley.com/2008/09/01/powershell-to-twitter/">Permalink</a> | Categories: <a href="http://andyoakley.com/category/powershell/" title="View all posts in Powershell" rel="category tag">Powershell</a>, <a href="http://andyoakley.com/category/technology/" title="View all posts in Technology" rel="category tag">Technology</a> | Tags: <a href="http://andyoakley.com/tag/powershell/" rel="tag">Powershell</a>, <a href="http://andyoakley.com/tag/twitter/" rel="tag">twitter</a>
</small></p>]]></content:encoded>
			<wfw:commentRss>http://andyoakley.com/2008/09/01/powershell-to-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
