<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>Powershell</title><link>http://www.agileprogrammer.com/oneagilecoder/category/142.aspx</link><description>Writing about powershell, sample scripts, etc.</description><managingEditor>Brian Button</managingEditor><dc:language>en-US</dc:language><generator>.Text Version 0.95.2005.109</generator><item><dc:creator>Brian Button</dc:creator><title>Slides from my powershell talk</title><link>http://www.agileprogrammer.com/oneagilecoder/archive/2007/10/31/23675.aspx</link><pubDate>Wed, 31 Oct 2007 20:30:00 GMT</pubDate><guid>http://www.agileprogrammer.com/oneagilecoder/archive/2007/10/31/23675.aspx</guid><wfw:comment>http://www.agileprogrammer.com/oneagilecoder/comments/23675.aspx</wfw:comment><comments>http://www.agileprogrammer.com/oneagilecoder/archive/2007/10/31/23675.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.agileprogrammer.com/oneagilecoder/comments/commentRss/23675.aspx</wfw:commentRss><trackback:ping>http://www.agileprogrammer.com/oneagilecoder/services/trackbacks/23675.aspx</trackback:ping><description>&lt;p&gt;
I gave an introduction to Powershell talk at the St. Louis .Net UG meeting on Monday, October 29th to about 70-80 people or so. I introduced basic concepts of powershell, talked about a few problems I had solved with it, and showed some simple scripts.
&lt;/p&gt;
&lt;p&gt;
At the end of the presentation, I promised to post &lt;a href="http://www.agilestl.com/downloads/IntroductionToPowershell.ppt"&gt;the slides&lt;/a&gt; by the end of this week, and I'm making it Wednesday night. Believe me when I say that me getting something finished early is a minor miracle :)&lt;/p&gt;

-- bab&lt;img src ="http://www.agileprogrammer.com/oneagilecoder/aggbug/23675.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Brian Button</dc:creator><title>Finding all Attribute types in an assembly through powershell</title><link>http://www.agileprogrammer.com/oneagilecoder/archive/2007/10/23/23621.aspx</link><pubDate>Tue, 23 Oct 2007 12:57:00 GMT</pubDate><guid>http://www.agileprogrammer.com/oneagilecoder/archive/2007/10/23/23621.aspx</guid><wfw:comment>http://www.agileprogrammer.com/oneagilecoder/comments/23621.aspx</wfw:comment><comments>http://www.agileprogrammer.com/oneagilecoder/archive/2007/10/23/23621.aspx#Feedback</comments><slash:comments>3</slash:comments><wfw:commentRss>http://www.agileprogrammer.com/oneagilecoder/comments/commentRss/23621.aspx</wfw:commentRss><trackback:ping>http://www.agileprogrammer.com/oneagilecoder/services/trackbacks/23621.aspx</trackback:ping><description>&lt;p&gt;I was using the new xunit.net testing framework, and I wanted to see a list of all the attributes they had. &lt;em&gt;This looks like a job for Powershell!!!&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;
[System.Reflection.Assembly]::LoadFile("pathToFile.dll").GetTypes() | where-object { $_ -match "Attribute" }
&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
That did the trick!
&lt;/p&gt;
-- bab&lt;img src ="http://www.agileprogrammer.com/oneagilecoder/aggbug/23621.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Brian Button</dc:creator><title>Finding installed products with uninstall instructions</title><link>http://www.agileprogrammer.com/oneagilecoder/archive/2007/10/22/23615.aspx</link><pubDate>Mon, 22 Oct 2007 20:35:00 GMT</pubDate><guid>http://www.agileprogrammer.com/oneagilecoder/archive/2007/10/22/23615.aspx</guid><wfw:comment>http://www.agileprogrammer.com/oneagilecoder/comments/23615.aspx</wfw:comment><comments>http://www.agileprogrammer.com/oneagilecoder/archive/2007/10/22/23615.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.agileprogrammer.com/oneagilecoder/comments/commentRss/23615.aspx</wfw:commentRss><trackback:ping>http://www.agileprogrammer.com/oneagilecoder/services/trackbacks/23615.aspx</trackback:ping><description>&lt;p&gt;I was repaving a machine the other day, and I had to load all my development tools. There were a bunch of them, and when I got finished, I noticed that IIS and SQL Server failed to install properly. So I uninstalled IIS and reinstalled it, no problem. SQL Server was another story. 
&lt;/p&gt;
&lt;p&gt;I uninstalled it, and it only went part way. Then I tried to reinstall it, and it said it was already installed. I went around and around like this a few time, with a few reboots thrown in for good measure.
&lt;/p&gt;
&lt;p&gt;About this time, I started to google around for how to manually uinstall SQL Server. I came across a KB article on msdn.com somewhere, and it said to crawl through the registry in HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall, inspect all the GUIDs found there for those that had a DisplayName that contained SQL Server as part of it. Once I found a matching GUID, I was to use the UninstallString to manually uninstall it. 
&lt;/p&gt;
&lt;p&gt;The only problem was that there were dozens of these GUIDs in there. I sure wasn't going to crawl through them all by hand.
&lt;/p&gt;
&lt;p&gt;So, what was a handy shell programmer to do? Well, I pulled out powershell and whipped up a script.
&lt;/p&gt;
&lt;code&gt;
dir HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall | foreach-object {get-itemproperty $_.PSPath} | where-object {$_.DisplayName -match "SQL Server"} | select-object DisplayName,uninstallstring
&lt;/code&gt;

&lt;p&gt;Taking this script apart, piece by piece...
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;dir HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall&lt;/em&gt; lists all the registry keys beneath that location. It doesn't just spit out a string name for each item like a Unix shell would, it returns a list of RegistryKey objects. These objects are passed to the next command in the pipeline...
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;foreach-object {get-itemproperty $_.PSPath}&lt;/em&gt; is basically a for loop over each of those objects. It looks at the PSPath property of the RegistryKey objects and calls get-itemproperty on that  path to return a list of registry items. 
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;where-object {$_.DisplayName -match "SQL Server"}&lt;/em&gt; selects just those registry items where the DisplayName property of the registry items match "SQL Server". Finally, we clean up the output...
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;select-object DisplayName,uninstallstring&lt;/em&gt; essentially takes the objects that are passed to it from the previous pipeline stage and slices them into smaller pieces, creating a new object for each object passed to it. The new object contains just the two properties specified on the command, DisplayPath and UninstallString. 
&lt;/p&gt;
&lt;p&gt;Running this command gives me this output:
&lt;/p&gt;
&lt;pre&gt;
DisplayName                                                 UninstallString
-----------                                                 ---------------
GDR 1406 for SQL Server Integration Services 2005 (64-bi... C:\WINDOWS\DTS9_KB932557_ENU_64\Hotfix.exe /Uninstall
GDR 1406 for SQL Server Notification Services 2005 (64-b... C:\WINDOWS\NS9_KB932557_ENU_64\Hotfix.exe /Uninstall
GDR 1406 for SQL Server Analysis Services 2005 (64-bit) ... C:\WINDOWS\OLAP9_KB932557_ENU_64\Hotfix.exe /Uninstall
GDR 1406 for SQL Server Reporting Services 2005 (64-bit)... C:\WINDOWS\RS9_KB932557_ENU_64\Hotfix.exe /Uninstall
GDR 1406 for SQL Server Database Services 2005 (64-bit) ... C:\WINDOWS\SQL9_KB932557_ENU_64\Hotfix.exe /Uninstall
GDR 1406 for SQL Server Tools and Workstation Components... C:\WINDOWS\SQLTools9_KB932557_ENU_64\Hotfix.exe /Uninstall
Microsoft SQL Server 2005 (64-bit)                          "C:\Program Files\Microsoft SQL Server\90\Setup Bootstra...
Microsoft SQL Server Setup Support Files (English)          MsiExec.exe /X{18C5A65B-0A39-40B5-B958-63055AFAB65C}
Microsoft SQL Server VSS Writer                             MsiExec.exe /I{50822200-2E95-4E62-A8D8-41C3B308DF5E}
Microsoft SQL Server 2005 Analysis Services (64-bit)        MsiExec.exe /I{54C2B4E9-DD13-4AA4-B09A-A6EF68F9359A}
Microsoft SQL Server Native Client                          MsiExec.exe /I{6E740973-8E71-42F9-A910-C18452E60450}
Microsoft SQL Server 2005 Integration Services (64-bit)     MsiExec.exe /I{8A52D844-0DA7-40B0-8602-0567C068C081}
Microsoft SQL Server 2005 Reporting Services (64-bit)       MsiExec.exe /I{BEE3EC3D-0C91-4A3E-A42C-7634D32968F4}
Microsoft SQL Server 2005 Backward compatibility            MsiExec.exe /I{C92556F2-4950-48CF-ABA3-F0026B05BCE8}
MySQL Server 5.0                                            MsiExec.exe /I{D84E063A-AE58-41AF-B6FC-313B12DC89A6}
Microsoft SQL Server 2005 Notification Services (64-bit)    MsiExec.exe /I{EA145881-7452-4004-80B9-971FC3D1D8D8}
Microsoft SQL Server 2005 (64-bit)                          MsiExec.exe /I{F14F2E25-99AF-42A9-977C-F6D0352DC59F}
Microsoft SQL Server 2005 Tools (64-bit)                    MsiExec.exe /I{FE7C8861-3195-4CA5-98EB-094652478192}
&lt;/pre&gt;

&lt;p&gt;which is exactly what I wanted to find out in the first place. If I wanted to go further, I could run the uninstall command for these things automatically, but since I only had about 3 items I had to reinstall in my case, doing it by hand was no big deal.&lt;/p&gt;

&lt;p&gt;Anyhow, consider this published so that when I need this trick next time, it will be waiting here, safe and sound, on my blog, ready for me to read again.&lt;/p&gt;

&lt;p&gt;-- bab&lt;/p&gt;&lt;img src ="http://www.agileprogrammer.com/oneagilecoder/aggbug/23615.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Brian Button</dc:creator><title>Another powershell quickie - removing all bin and obj directories beneath VS.Net projects</title><link>http://www.agileprogrammer.com/oneagilecoder/archive/2007/06/23/22919.aspx</link><pubDate>Sat, 23 Jun 2007 10:32:00 GMT</pubDate><guid>http://www.agileprogrammer.com/oneagilecoder/archive/2007/06/23/22919.aspx</guid><wfw:comment>http://www.agileprogrammer.com/oneagilecoder/comments/22919.aspx</wfw:comment><comments>http://www.agileprogrammer.com/oneagilecoder/archive/2007/06/23/22919.aspx#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.agileprogrammer.com/oneagilecoder/comments/commentRss/22919.aspx</wfw:commentRss><trackback:ping>http://www.agileprogrammer.com/oneagilecoder/services/trackbacks/22919.aspx</trackback:ping><description>&lt;p&gt;&lt;font face="Courier New"&gt;gci -recurse -include bin,obj . | ri -recurse&lt;/font&gt;&lt;/p&gt; &lt;p&gt;I was playing around with how to get this to work, and I couldn't seem to figure out why these commands didn't find the same locations to delete:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;font face="courier new"&gt;gci -recurse -include bin,obj .&lt;/font&gt;&lt;/li&gt; &lt;li&gt;&lt;font face="courier new"&gt;ri -recurse -force -include bin,obj -whatif .&lt;/font&gt;&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;I finally got so baffled that I RTFMed remove-item, and there was my answer. In the fine print, nestled away in an example that did what I was looking for, and in the documentation for the recurse parameter was my answer...&lt;/p&gt; &lt;p&gt;&lt;em&gt;-recurse &amp;lt;SwitchParameter&amp;gt;&lt;br&gt;Deletes the items in the specified locations and in all child items of the locations. &lt;/em&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;The Recurse parameter in this cmdlet does not work properly.&lt;/strong&gt;&lt;/em&gt;  &lt;p&gt;Ah ha! That's when I went to the format that I finally settled on, and everything worked. &lt;p&gt;Another blog posting mostly written to help me remember how I solved this problem the next time I encounter it! &lt;p&gt;-- bab&lt;img src ="http://www.agileprogrammer.com/oneagilecoder/aggbug/22919.aspx" width = "1" height = "1" /&gt;</description></item><item><dc:creator>Brian Button</dc:creator><title>find -name foo.\* | xargs grep &amp;quot;find_me&amp;quot;</title><link>http://www.agileprogrammer.com/oneagilecoder/archive/2007/03/22/22509.aspx</link><pubDate>Thu, 22 Mar 2007 16:50:00 GMT</pubDate><guid>http://www.agileprogrammer.com/oneagilecoder/archive/2007/03/22/22509.aspx</guid><wfw:comment>http://www.agileprogrammer.com/oneagilecoder/comments/22509.aspx</wfw:comment><comments>http://www.agileprogrammer.com/oneagilecoder/archive/2007/03/22/22509.aspx#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.agileprogrammer.com/oneagilecoder/comments/commentRss/22509.aspx</wfw:commentRss><trackback:ping>http://www.agileprogrammer.com/oneagilecoder/services/trackbacks/22509.aspx</trackback:ping><description>&lt;p&gt;&lt;strong&gt;[Update from Brad Wilson and Scott Dukes]&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;I've been wanting a powershell script to replace my favorite unix command for ages, and I took a stab at it today. This got me very close to what I wanted yesterday, which was just the names of files where the matches occurred. &lt;/p&gt;&lt;pre&gt;get-childitem -include foo.* -recurse | where-object { get-content $_ | select-string find_me }&lt;/pre&gt;
&lt;p&gt;Scott Dukes pointed out that select-string would take the FileInfo object that was passed to it and search through the contents for the string file_me, and this would give me the exact same kind of output my unix command used to. Thanks, Scott! This command was exactly what I needed.&lt;/p&gt;
&lt;p&gt;Brad went &lt;em&gt;way&lt;/em&gt; past this and showed some &lt;a href="http://feeds.feedburner.com/~r/BradWilson-ThenetGuy/~3/103713896/22511.aspx"&gt;very interesting other changes to the script&lt;/a&gt; to do some cool things.&lt;/p&gt;
&lt;p&gt;Thanks again to both of them for correcting this PowerShell newbie. I've been a long-time Unix scripting weenie, with bash code flowing out my fingertips at will (in XEmacs of course :)), but I think PowerShell just blows that away. &lt;/p&gt;
&lt;p&gt;-- bab&lt;/p&gt;&lt;img src ="http://www.agileprogrammer.com/oneagilecoder/aggbug/22509.aspx" width = "1" height = "1" /&gt;</description></item></channel></rss>