<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/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>PowerShell</title>
        <link>http://geekswithblogs.net/Lance/category/5727.aspx</link>
        <description>Microsoft Windows PowerShell</description>
        <language>en-US</language>
        <copyright>Lance Robinson</copyright>
        <managingEditor>lmrobins@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Creating Team Foundation Work Items With PowerShell</title>
            <link>http://geekswithblogs.net/Lance/archive/2011/01/26/creating-team-foundation-work-items-with-powershell.aspx</link>
            <description>&lt;p&gt;Here is the simple function I added to my powershell profile:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="width: 80%; margin-left: auto; margin-right: auto"&gt;
&lt;div class="psheader-left"&gt; &lt;/div&gt;
&lt;div class="psheader-right"&gt; &lt;/div&gt;
&lt;div class="psheader-middle"&gt; &lt;/div&gt;
&lt;div&gt;
&lt;div class="psbody-left"&gt; &lt;/div&gt;
&lt;div class="psbody-right"&gt; &lt;/div&gt;
&lt;div class="psbody-middle"&gt;
&lt;div class="psscriptscrollarea"&gt;
&lt;p&gt; &lt;/p&gt;
&lt;pre&gt;
function create-tfstask ($desc) {
 tfpt workitem /new $workItemType /collection:$serverUrl /fields:"Title=$($desc);Assigned To=$assignee;AreaId=$areaId;IterationId=$iterationId"
}&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style="width: 100%"&gt;
&lt;div class="psfooter-left"&gt; &lt;/div&gt;
&lt;div class="psfooter-right"&gt; &lt;/div&gt;
&lt;div class="psfooter-middle"&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;To find the AreaId and IterationId for your project/versions, just look at a bug you know is setup correctly:&lt;/p&gt;
&lt;p&gt;PS C:\&amp;gt; tfpt query /collection:&lt;a href="http://3bs001vsteam:8080/tfs"&gt;http://3bs001vsteam:8080/tfs&lt;/a&gt; /wiql:"select AreaId,IterationId from workitems where ID = 879"&lt;/p&gt;
&lt;p&gt;Next I hooked this into &lt;a href="http://lancerobinson.net/archive/2010/10/26/quick-powershell-ldquotodordquo-gmail-emailer.aspx"&gt;my existing "todo" function&lt;/a&gt; by adding a new case in its $target switch statement for “tfs”, which calls my create-tfstask function and returns.  Updated todo function:&lt;/p&gt;
&lt;div style="width: 80%; margin-left: auto; margin-right: auto"&gt;
&lt;div class="psheader-left"&gt; &lt;/div&gt;
&lt;div class="psheader-right"&gt; &lt;/div&gt;
&lt;div class="psheader-middle"&gt; &lt;/div&gt;
&lt;div&gt;
&lt;div class="psbody-left"&gt; &lt;/div&gt;
&lt;div class="psbody-right"&gt; &lt;/div&gt;
&lt;div class="psbody-middle"&gt;
&lt;div class="psscriptscrollarea"&gt;
&lt;pre&gt;
function todo {
  param([string] $target = "work",
        [string] $msg )
			
  $emailFrom = "lance@3birdsmarketing.com"
	
  #combine all the cmd line args into one "message"
  if ($args -ne "") {
    $msg = $msg + " " + $args
  }
	
  #what is the target of the message?
  switch ($target)
  {
    "work" { $target = "lance@3birdsmarketing.com" }
    "home" { $target = "lmrobins@gmail.com" }
    "tfs" { create-tfstask $msg; return }
  }	
	
  $subject = "Todo: " + $msg
  $body = $msg
  $smtpServer = "3bs001exch"	
  $smtp = new-object Net.Mail.SmtpClient($smtpServer, 25)
  $smtp.Send($emailFrom, $target, $subject, $body)
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style="width: 100%"&gt;
&lt;div class="psfooter-left"&gt; &lt;/div&gt;
&lt;div class="psfooter-right"&gt; &lt;/div&gt;
&lt;div class="psfooter-middle"&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:8cb4d90c-7189-41e7-b9ab-c330c875c6d7" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px"&gt;Technorati Tags: &lt;a rel="tag" href="http://technorati.com/tags/PowerShell"&gt;PowerShell&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/TFS"&gt;TFS&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/Team+Foundation"&gt;Team Foundation&lt;/a&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/143640.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2011/01/26/creating-team-foundation-work-items-with-powershell.aspx</guid>
            <pubDate>Wed, 26 Jan 2011 15:58:22 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/143640.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2011/01/26/creating-team-foundation-work-items-with-powershell.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/143640.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/143640.aspx</trackback:ping>
        </item>
        <item>
            <title>PowerShell &amp;ndash; Recycle All IIS App Pools</title>
            <link>http://geekswithblogs.net/Lance/archive/2010/12/16/powershell-ndash-recycle-all-iis-app-pools.aspx</link>
            <description>&lt;p&gt;With a little help from Shay Levy’s post on Stack Overflow and the MSDN documentation, I added this handy function to my profile to automatically recycle all IIS app pools.&lt;/p&gt;
&lt;div style="width: 80%; margin-left: auto; margin-right: auto;"&gt;
&lt;div class="psheader-left"&gt; &lt;/div&gt;
&lt;div class="psheader-right"&gt; &lt;/div&gt;
&lt;div class="psheader-middle"&gt; &lt;/div&gt;
&lt;div&gt;
&lt;div class="psbody-left"&gt; &lt;/div&gt;
&lt;div class="psbody-right"&gt; &lt;/div&gt;
&lt;div class="psbody-middle"&gt;
&lt;div class="psscriptscrollarea"&gt;
&lt;pre style="border: 1px solid rgb(206, 206, 206); padding: 5px; background-color: rgb(251, 251, 251); min-height: 40px; width: 650px; overflow: auto;"&gt;&lt;pre style="background-color: rgb(251, 251, 251); margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px;"&gt;
function Recycle-AppPools {
  
    param(
    [string] $server = "3bhs001",
    [int] $mode = 1, # ManagedPipelineModes: 0 = integrated, 1 = classic
    ) &lt;p&gt; $iis = [adsi]"IIS://$server/W3SVC/AppPools"&lt;br /&gt; $iis.psbase.children | %{ &lt;br /&gt;   $pool = [adsi]($_.psbase.path); &lt;br /&gt;   if ($pool.AppPoolState -eq 2 -and $pool.ManagedPipelineMode -eq $mode) {&lt;br /&gt;     # AppPoolStates:  1 = starting, 2 = started, 3 = stopping, 4 = stopped          &lt;br /&gt;     $pool.psbase.invoke("recycle") &lt;br /&gt;     }&lt;br /&gt;   }&lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;/pre&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style="width: 100%;"&gt;
&lt;div class="psfooter-left"&gt; &lt;/div&gt;
&lt;div class="psfooter-right"&gt; &lt;/div&gt;
&lt;div class="psfooter-middle"&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/143156.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2010/12/16/powershell-ndash-recycle-all-iis-app-pools.aspx</guid>
            <pubDate>Thu, 16 Dec 2010 20:59:17 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/143156.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2010/12/16/powershell-ndash-recycle-all-iis-app-pools.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/143156.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/143156.aspx</trackback:ping>
        </item>
        <item>
            <title>Quick PowerShell &amp;ldquo;Todo&amp;rdquo; Gmail Emailer</title>
            <link>http://geekswithblogs.net/Lance/archive/2010/10/26/quick-powershell-ldquotodordquo-gmail-emailer.aspx</link>
            <description>&lt;p&gt;I put the following function in my PowerShell profile so that I can just bring up my PowerShell console and type myself a quick “todo” note that automatically gets emailed to me for later.  There are several things of note in this tiny script:&lt;/p&gt;  &lt;p&gt;1.  Note the use of the $args variable to effectively allow the user to enter $msg parameter without quotes even if it contains whitespace.&lt;/p&gt;  &lt;p&gt;2.  In this particular example I’m sending the email through Gmail.  smtp.gmail.com, port 587, SSL and authentication required.&lt;/p&gt;  &lt;p&gt;3.  Check outhe $gmailcred variable, which gets set earlier in my profile.  It &lt;a href="http://lancerobinson.net/archive/2007/02/16/106518.aspx"&gt;gets read from a secure string file&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div style="width: 80%; margin-left: auto; margin-right: auto"&gt;   &lt;div class="psheader-left"&gt; &lt;/div&gt;    &lt;div class="psheader-right"&gt; &lt;/div&gt;    &lt;div class="psheader-middle"&gt; &lt;/div&gt;    &lt;div&gt;     &lt;div class="psbody-left"&gt; &lt;/div&gt;      &lt;div class="psbody-right"&gt; &lt;/div&gt;      &lt;div class="psbody-middle"&gt;       &lt;div class="psscriptscrollarea"&gt;         &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;function todo {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  param([&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;] $target = "&lt;span style="color: #8b0000"&gt;work&lt;/span&gt;",
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        [&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;] $msg )
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; ($target)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  "&lt;span style="color: #8b0000"&gt;work&lt;/span&gt;" { $target = "&lt;span style="color: #8b0000"&gt;lance@3birdsmarketing.com&lt;/span&gt;" }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  "&lt;span style="color: #8b0000"&gt;home&lt;/span&gt;" { $target = "&lt;span style="color: #8b0000"&gt;lmrobins@gmail.com&lt;/span&gt;" }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  $emailFrom = "&lt;span style="color: #8b0000"&gt;lmrobins@gmail.com&lt;/span&gt;"
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ($args -ne "&lt;span style="color: #8b0000"&gt;&lt;/span&gt;") {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    $msg = $msg + "&lt;span style="color: #8b0000"&gt; &lt;/span&gt;" + $args
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  $subject = "&lt;span style="color: #8b0000"&gt;Todo: &lt;/span&gt;" + $msg
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  $body = $msg
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  $smtpServer = "&lt;span style="color: #8b0000"&gt;smtp.gmail.com&lt;/span&gt;"  
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  $smtp = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt;-&lt;span style="color: #0000ff"&gt;object&lt;/span&gt; Net.Mail.SmtpClient($smtpServer, 587)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  $smtp.EnableSsl = $&lt;span style="color: #0000ff"&gt;true&lt;/span&gt;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  $smtp.Credentials = [Net.NetworkCredential]($gmailcred)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;  $smtp.Send($emailFrom, $target, $subject, $body)
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;div style="width: 100%"&gt;
    &lt;div class="psfooter-left"&gt; &lt;/div&gt;

    &lt;div class="psfooter-right"&gt; &lt;/div&gt;

    &lt;div class="psfooter-middle"&gt; &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:57dc0975-ec20-49da-bd4e-a0f1849f151b" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Gmail" rel="tag"&gt;Gmail&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Parameters" rel="tag"&gt;Parameters&lt;/a&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/142452.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2010/10/26/quick-powershell-ldquotodordquo-gmail-emailer.aspx</guid>
            <pubDate>Tue, 26 Oct 2010 17:27:13 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/142452.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2010/10/26/quick-powershell-ldquotodordquo-gmail-emailer.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/142452.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/142452.aspx</trackback:ping>
        </item>
        <item>
            <title>PowerShell TruncateAtWhitespace Function</title>
            <link>http://geekswithblogs.net/Lance/archive/2010/08/16/powershell-truncateatwhitespace-function.aspx</link>
            <description>&lt;p&gt;Here’s a TruncateAtWhitespace function that takes an incoming parameter value and an incoming max length, and returns a substring broken at a whitespace position.  This way if you have “Lance has a blog” and you need to truncate it to 8 characters or less, you get “Lance” instead of “Lance ha”.&lt;/p&gt;  &lt;pre style="border-bottom: #cecece 1px solid; border-left: #cecece 1px solid; padding-bottom: 5px; background-color: #fbfbfb; min-height: 40px; padding-left: 5px; width: 650px; padding-right: 5px; overflow: auto; border-top: #cecece 1px solid; border-right: #cecece 1px solid; padding-top: 5px"&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;function TruncateAtWhitespace{
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    param(
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        [&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;]$&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;,
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;        [&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;]$maxlength=200
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    )
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    $maxlength-=3; #allow &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; "&lt;span style="color: #8b0000"&gt;...&lt;/span&gt;" suffix
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ($&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;.Length -le $maxlength) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;      &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; ($&lt;span style="color: #0000ff"&gt;value&lt;/span&gt; + "&lt;span style="color: #8b0000"&gt;...&lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    $closestwhitespaceindex = [&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;]$&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;.Substring(0, $maxlength).LastIndexOf("&lt;span style="color: #8b0000"&gt; &lt;/span&gt;");
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ($closestwhitespaceindex -gt 0) {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;      $&lt;span style="color: #0000ff"&gt;value&lt;/span&gt; = $&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;.Substring(0, $closestwhitespaceindex) + "&lt;span style="color: #8b0000"&gt;...&lt;/span&gt;";
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    } &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; {
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;      $&lt;span style="color: #0000ff"&gt;value&lt;/span&gt; = $&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;.Substring(0, $maxlength);
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    }
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; $&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
&lt;/pre&gt;&lt;pre style="background-color: #fbfbfb; margin: 0em; width: 100%; font-family: consolas,'Courier New',courier,monospace; font-size: 12px"&gt;}&lt;/pre&gt;&lt;/pre&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:dee978aa-edc6-4e5a-a49a-64642738047e" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/141340.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2010/08/16/powershell-truncateatwhitespace-function.aspx</guid>
            <pubDate>Mon, 16 Aug 2010 19:30:13 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/141340.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2010/08/16/powershell-truncateatwhitespace-function.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/141340.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/141340.aspx</trackback:ping>
        </item>
        <item>
            <title>Exception setting &amp;quot;ThreadOptions&amp;quot; in SharePoint 2010 Management Shell</title>
            <link>http://geekswithblogs.net/Lance/archive/2010/02/17/exception-setting-quotthreadoptionsquot-in-sharepoint-2010-management-shell.aspx</link>
            <description>&lt;p&gt;Right after you install SP2010 (Foundation or Server), even on a completely updated Windows Server 2008 SP2, when you go to start the SharePoint 2010 Management Shell (the recommended PowerShell interface for working with SharePoint), you get a real ugly looking error:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Exception setting "ThreadOptions": "This property cannot be changed after the Runspace has been opened."       &lt;br /&gt;At C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONF        &lt;br /&gt;IG\POWERSHELL\Registration\SharePoint.ps1:2 char:48        &lt;br /&gt;+ if ($ver.Version.Major -gt 1)  {$Host.Runspace. &amp;lt;&amp;lt;&amp;lt;&amp;lt; ThreadOptions = "ReuseTh        &lt;br /&gt;read"}        &lt;br /&gt;    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException        &lt;br /&gt;    + FullyQualifiedErrorId : PropertyAssignmentException&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;To get around this problem, update the Windows Management Framework Core.  &lt;a href="http://support.microsoft.com/default.aspx/kb/968930"&gt;See KB968930&lt;/a&gt;, where you can download updates for various versions of Windows.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/Lance/WindowsLiveWriter/ExceptionsettingThreadOptionsinSharePoin_C392/sp2010mgmtshell.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="sp2010mgmtshell" border="0" alt="sp2010mgmtshell" src="http://geekswithblogs.net/images/geekswithblogs_net/Lance/WindowsLiveWriter/ExceptionsettingThreadOptionsinSharePoin_C392/sp2010mgmtshell_thumb.png" width="644" height="323" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:bf047895-a51b-432f-95da-e0622b5d2cec" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/SharePoint" rel="tag"&gt;SharePoint&lt;/a&gt;,&lt;a href="http://technorati.com/tags/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SharePoint+2010+Management+Shell" rel="tag"&gt;SharePoint 2010 Management Shell&lt;/a&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/138022.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2010/02/17/exception-setting-quotthreadoptionsquot-in-sharepoint-2010-management-shell.aspx</guid>
            <pubDate>Wed, 17 Feb 2010 18:56:51 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/138022.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2010/02/17/exception-setting-quotthreadoptionsquot-in-sharepoint-2010-management-shell.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/138022.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/138022.aspx</trackback:ping>
        </item>
        <item>
            <title>PowerShell: Twitter Auto UN-follow</title>
            <link>http://geekswithblogs.net/Lance/archive/2010/01/12/powershell-twitter-auto-un-follow.aspx</link>
            <description>&lt;p&gt;Anybody who uses Twitter has heard of auto-follow services for Twitter.&lt;/p&gt;
&lt;p&gt;Below is a PowerShell script I used to auto UNfollow.  The script goes through the people you're following and eliminates "idle" or "spam" friends.  An idle friend is determined by a low friend count or low status count on an account that has been in existance for at least a couple months (configurable).  A spam friend is determined by a high friend count but a low follower count (by default, the script uses a 15-1 ratio as the max).&lt;/p&gt;
&lt;p&gt;I would appreciate any good tweaks or improvements you might like to share!  In particular I wasn't sure how to deal with Twitter's rate limiting (150 get requests per hour).  For now I just catch the exception when it occurs and sleep for an hour before resuming.&lt;/p&gt;
&lt;div style="width: 80%; margin-left: auto; margin-right: auto;"&gt;
&lt;div class="psheader-left"&gt; &lt;/div&gt;
&lt;div class="psheader-right"&gt; &lt;/div&gt;
&lt;div class="psheader-middle"&gt; &lt;/div&gt;
&lt;div&gt;
&lt;div class="psbody-left"&gt; &lt;/div&gt;
&lt;div class="psbody-right"&gt; &lt;/div&gt;
&lt;div class="psbody-middle"&gt;
&lt;div class="psscriptscrollarea"&gt;
&lt;pre class="csharpcode"&gt;
#&lt;span class="kwrd"&gt;this&lt;/span&gt; script goes through the people you're following and eliminates &lt;span class="str"&gt;"idle"&lt;/span&gt; or &lt;span class="str"&gt;"spam"&lt;/span&gt; friends.
#an idle friend &lt;span class="kwrd"&gt;is&lt;/span&gt; determined by low friends or statuses on an account that has been &lt;span class="kwrd"&gt;in&lt;/span&gt; existance &lt;span class="kwrd"&gt;for&lt;/span&gt; a &lt;span class="kwrd"&gt;while&lt;/span&gt;
#a spam friend &lt;span class="kwrd"&gt;is&lt;/span&gt; determined by high friends but low followers

param([&lt;span class="kwrd"&gt;int&lt;/span&gt;] $minfriends = 20,
        [&lt;span class="kwrd"&gt;int&lt;/span&gt;] $minstatuses = 20,
        [&lt;span class="kwrd"&gt;int&lt;/span&gt;] $minaccountage = 60, #days
        [&lt;span class="kwrd"&gt;int&lt;/span&gt;] $maxratio = 15,
        [&lt;span class="kwrd"&gt;switch&lt;/span&gt;] $silent = $&lt;span class="kwrd"&gt;false&lt;/span&gt; #whether or not to prompt before unfollowing
        )

function unfollow($userid, $userinfo) {
    &lt;span class="kwrd"&gt;do&lt;/span&gt; {
        Write-Host &lt;span class="str"&gt;"Unfollowing User $($userinfo.user.screen_name): $($userinfo.user.friends_count) friends/$($userinfo.user.followers_count) followers/$($userinfo.user.statuses_count) statuses [y/n/l]: "&lt;/span&gt; -noNewLine -foregroundColor Yellow
        &lt;span class="kwrd"&gt;if&lt;/span&gt; ($silent -eq $&lt;span class="kwrd"&gt;false&lt;/span&gt;) {
            $cmd = Read-Host
        }
        &lt;span class="kwrd"&gt;if&lt;/span&gt; ($silent -eq $&lt;span class="kwrd"&gt;true&lt;/span&gt; -or $cmd -eq &lt;span class="str"&gt;"y"&lt;/span&gt;) {
            $wc = &lt;span class="kwrd"&gt;new&lt;/span&gt;-&lt;span class="kwrd"&gt;object&lt;/span&gt; net.webclient
            $wc.Credentials = $global:twittercred
            $unfollo = $wc.UploadString(&lt;span class="str"&gt;"http://www.twitter.com/friendships/destroy/$($userid).xml"&lt;/span&gt;, &lt;span class="str"&gt;""&lt;/span&gt;)                
            $unfollow.user.following            
        }
        &lt;span class="kwrd"&gt;if&lt;/span&gt; ($cmd -eq &lt;span class="str"&gt;"l"&lt;/span&gt;) {
            Start-Process &lt;span class="str"&gt;"http://www.twitter.com/$($userinfo.user.screen_name)"&lt;/span&gt;
        }
    } &lt;span class="kwrd"&gt;while&lt;/span&gt; ($silent -eq $&lt;span class="kwrd"&gt;false&lt;/span&gt; -and $cmd -eq &lt;span class="str"&gt;"l"&lt;/span&gt;)
}

#enter your Twitter credentials &lt;span class="kwrd"&gt;for&lt;/span&gt; retrieving your friends list
$global:twittercred = Get-Credential

#retrieve the full friends list
$wc = &lt;span class="kwrd"&gt;new&lt;/span&gt;-&lt;span class="kwrd"&gt;object&lt;/span&gt; net.webclient
$wc.Credentials = $global:twittercred
$response = [xml]($wc.DownloadString(&lt;span class="str"&gt;"http://www.twitter.com/friends/ids.xml"&lt;/span&gt;))

#now loop through each friend
$response.ids.id | % {
    &lt;span class="kwrd"&gt;try&lt;/span&gt;
    {
        #get detailed info about &lt;span class="kwrd"&gt;this&lt;/span&gt; user
        $showuser = [xml]($wc.DownloadString(&lt;span class="str"&gt;"http://www.twitter.com/users/show.xml?id=$($_)"&lt;/span&gt;))
    } &lt;span class="kwrd"&gt;catch&lt;/span&gt; {
        Write-Host &lt;span class="str"&gt;"Twitter rate limit reached (150 gets/hour).  Pausing for one hour..."&lt;/span&gt; -foregroundColor Red -noNewLine
        Start-Sleep -Seconds 3600
    }
    #determine &lt;span class="kwrd"&gt;if&lt;/span&gt; they are worthy of following:
     $datecreated = [DateTime]::ParseExact($showuser.user.created_at, &lt;span class="str"&gt;"ddd MMM dd H:mm:ss +0000 yyyy"&lt;/span&gt;, [System.Globalization.CultureInfo]::InvariantCulture)
     $accountage = ([DateTime]::Now).Subtract($datecreated).Days    
    $statusescount = [&lt;span class="kwrd"&gt;int&lt;/span&gt;]$showuser.user.statuses_count
    $friendscount = [&lt;span class="kwrd"&gt;int&lt;/span&gt;]$showuser.user.friends_count
    $followerscount = [&lt;span class="kwrd"&gt;int&lt;/span&gt;]$showuser.user.followers_count
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (($accountage -ge $minaccountage) -and ($friendscount -lt $minfriends -or $statusescount -lt $minstatuses)) {
        #unfollow idle friends:
        unfollow $_ $showuser
    }
    elseif (($accountage -ge $minaccountage -and $followerscount -eq 0) -or ($followerscount -gt 0 -and $friendscount / $followerscount -gt $maxratio)) {
        #unfollow spam friends:
        unfollow $_ $showuser
    }    
    &lt;span class="kwrd"&gt;else&lt;/span&gt; {
        Write-Host &lt;span class="str"&gt;"Good friend $($showuser.user.screen_name): $($friendscount)/$($friendscount)/$($statusescount): "&lt;/span&gt;
    }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style="width: 100%;"&gt;
&lt;div class="psfooter-left"&gt; &lt;/div&gt;
&lt;div class="psfooter-right"&gt; &lt;/div&gt;
&lt;div class="psfooter-middle"&gt; &lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:a2a26dbc-907f-4218-adaf-08150f6d9c74" style="margin: 0px; padding: 0px; display: inline; float: none;"&gt;Technorati Tags: &lt;a rel="tag" href="http://technorati.com/tags/Twitter"&gt;Twitter&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/PowerShell"&gt;PowerShell&lt;/a&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/137449.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2010/01/12/powershell-twitter-auto-un-follow.aspx</guid>
            <pubDate>Tue, 12 Jan 2010 18:06:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/137449.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2010/01/12/powershell-twitter-auto-un-follow.aspx#feedback</comments>
            <slash:comments>4</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/137449.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/137449.aspx</trackback:ping>
        </item>
        <item>
            <title>Program Files Environment Variable in PowerShell</title>
            <link>http://geekswithblogs.net/Lance/archive/2009/12/29/program-files-environment-variable-in-powershell.aspx</link>
            <description>&lt;p&gt;Today I saw this on Twitter from Julie Blender (@#juneb_get_help): &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Need to reference the "ProgramFiles(x86)" environment variable in &lt;/em&gt;&lt;a href="http://hootsuite.com/dashboard#"&gt;&lt;em&gt;#PowerShell?&lt;/em&gt;&lt;/a&gt;&lt;em&gt; Use ${env:ProgramFiles(x86)}.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I use this in a lot of my scripts, but I want a single variable that contains the right value whether I'm in a 64 bit shell or not.  Here's my solution:&lt;/p&gt;
&lt;p&gt;First, I have a function in my testing profile called is64bit, that looks like this:&lt;/p&gt;
&lt;div class="psscrollarea"&gt;
&lt;pre&gt;
function is64bit() {
  &lt;span class="kwrd"&gt;return&lt;/span&gt; ([IntPtr]::Size -eq 8)
}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, I have a get-programfilesdir function that I call that checks whether or not I'm in a 64 bit shell or not and returns the appropriate program files environment variable (ie, if I'm running on a 64 bit machine it will return "C:\Program Files (x86)", but if I'm running on a 32 bit machine it will return "C:\Program Files".  If I'm running in a 32 or 64 bit shell on a 64 bit machine, it will always return "C:\Program Files (x86)".&lt;/p&gt;
&lt;div class="psscrollarea"&gt;
&lt;pre&gt;
function get-programfilesdir() {
  &lt;span class="kwrd"&gt;if&lt;/span&gt; (is64bit -eq $&lt;span class="kwrd"&gt;true&lt;/span&gt;) {
    (Get-Item &lt;span class="str"&gt;"Env:ProgramFiles(x86)"&lt;/span&gt;).Value
  }
  &lt;span class="kwrd"&gt;else&lt;/span&gt; {
    (Get-Item &lt;span class="str"&gt;"Env:ProgramFiles"&lt;/span&gt;).Value
  }
}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:4c350768-103d-401f-bd66-2179e2a576c8" style="margin: 0px; padding: 0px; display: inline; float: none;"&gt;Technorati Tags: &lt;a rel="tag" href="http://technorati.com/tags/PowerShell"&gt;PowerShell&lt;/a&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/137252.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2009/12/29/program-files-environment-variable-in-powershell.aspx</guid>
            <pubDate>Tue, 29 Dec 2009 12:27:08 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/137252.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2009/12/29/program-files-environment-variable-in-powershell.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/137252.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/137252.aspx</trackback:ping>
        </item>
        <item>
            <title>10 PowerShell One Liners</title>
            <link>http://geekswithblogs.net/Lance/archive/2009/12/29/10-powershell-one-liners.aspx</link>
            <description>&lt;p&gt;Here are a few one-liners that use &lt;a href="http://www.nsoftware.com/powershell"&gt;NetCmdlets&lt;/a&gt;. Some of these I've blogged about before, some are new. Let me know if you have questions, which ones you find useful, or how you altered these to suit your own needs. &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Send email to a list of recipient addresses:      &lt;br /&gt;      &lt;br /&gt;import-csv users.csv | % { send-email -to $_.email -from lance@nsoftware.com -subject "Important Email" –message "Hello World!" -server 10.0.1.1 }       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Show the access control list for a specific Exchange folder:      &lt;br /&gt;      &lt;br /&gt;get-imap -server $mymailserver -cred $mycred -folder INBOX.RESUMES –acl       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Add look and read permissions on an Exchange folder, for a list of accounts pulled from a CSV file:      &lt;br /&gt;      &lt;br /&gt;import-csv users.csv | % { set-imap -server -acluser $_.username $mymailserver -cred $mycred -folder INBOX.RESUMES –acl “lr”  }       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Sync system time with an Internet time server:      &lt;br /&gt;      &lt;br /&gt;get-time -server clock.psu.edu –set       &lt;br /&gt;      &lt;br /&gt;To remotely sync the time on a set of computers:       &lt;br /&gt;      &lt;br /&gt;import-csv computers.csv | % { Invoke-Command -computerName $_.computer -cred $mycred -scriptblock { get-time -server clock.psu.edu –set } }       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Delete all emails from an Exchange folder that match a certain criteria.  For example, delete all emails from alf@email.com:      &lt;br /&gt;      &lt;br /&gt;get-imap -server $mailserver –cred $mycred | ? {$_.FromEmail -eq alff@email.com} | %{ set-imap -server $mailserver –cred $mycred-message $_.Id -delete }       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Update Twitter status from PowerShell:      &lt;br /&gt;      &lt;br /&gt;get-http –url "http://twitter.com/statuses/update.xml" –cred $mycred -variablename status -variablevalue "Tweeting with NetCmdlets!"       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;A test-path that works over FTP, FTPS (SSL), and SFTP (SSH) connections:      &lt;br /&gt;      &lt;br /&gt;get-ftp -server $remoteserver –cred $mycred -path /remote/path/to/checkfor*       &lt;br /&gt;      &lt;br /&gt;Don't forget the *.  Also, to use SSL or SSH just add an –ssl or –ssh parameter.       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;List disabled user accounts in Active Directory (or any other LDAP server):      &lt;br /&gt;      &lt;br /&gt;get-ldap -server $ad -cred $mycred -dn dc=yourdc -searchscope wholesubtree       &lt;br /&gt;    -search "(&amp;amp;(objectclass=user)(objectclass=person)(company=*)(userAccountControl:1.2.840.113556.1.4.803:=2))"       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;List Active Directory groups and their members:      &lt;br /&gt;      &lt;br /&gt;get-ldap -server testman -cred $mycred -dn dc=NS2 -searchscope wholesubtree -search "(&amp;amp;(objectclass=group)(cn=*admin*))" | select ResultDN, member       &lt;br /&gt;&lt;/li&gt;    &lt;li&gt;Display the last initialization time (e.g. last reboot time) of all discoverable SNMP agents on a network:      &lt;br /&gt;      &lt;br /&gt;import-csv computers.csv | % { get-snmp -agent $_.computer -oid sysUpTime.0 | %{([datetime]::Now).AddSeconds(-($_.OIDValue/100))} }       &lt;br /&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Not mentioned here:  data conversion (Yenc, QP, UUencoding, MD5, SHA1, base64, etc), DNS, News Groups (NNTP/UseNet), POP mail, RSS feeds, Amazon S3, Syslog, TFTP, TraceRoute, SNMP Traps, UDP, WebDAV, whois, Rexec/Rshell/Telnet, Zip files, sending IMs (Jabber/GoogleTalk/XMPP), sending text messages and pages, ping, and more.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:712616c9-a0fc-44d0-ac16-20d7631bdf48" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;,&lt;a href="http://technorati.com/tags/NetCmdlets" rel="tag"&gt;NetCmdlets&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Active+Directory" rel="tag"&gt;Active Directory&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Exchange" rel="tag"&gt;Exchange&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Oneliners" rel="tag"&gt;Oneliners&lt;/a&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/137250.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2009/12/29/10-powershell-one-liners.aspx</guid>
            <pubDate>Tue, 29 Dec 2009 09:36:37 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/137250.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2009/12/29/10-powershell-one-liners.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/137250.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/137250.aspx</trackback:ping>
        </item>
        <item>
            <title>PowerShell: Smart Parameter Expressions</title>
            <link>http://geekswithblogs.net/Lance/archive/2009/12/08/powershell-smart-parameter-expressions.aspx</link>
            <description>&lt;p&gt;A while back I posted about &lt;a href="http://geekswithblogs.net/Lance/archive/2007/12/14/powershell-script---marking-a-parameter-as-required.aspx"&gt;how to mark a script parameter as required in PowerShell&lt;/a&gt;.  Shortly afterwards, there was some chatter on it that I think makes it worthwhile to add another post on the subject of PowerShell script parameters.&lt;/p&gt;
&lt;p&gt;Let’s say you have the question:  “Can I do &amp;lt;X&amp;gt; with a parameter?” &lt;/p&gt;
&lt;p&gt;The answer is probably “Yes”.  :)&lt;/p&gt;
&lt;p&gt;Jim and an anonymous emailer both asked:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Is there any way you can specify a parameter based on the value of another parameter?&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The answer is yes.  You can put pretty much any expression in the default evaluator of the parameter definition. For example:&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div class="psscrollarea"&gt;
&lt;pre&gt;
  param(
    [switch] $switchparam, #an optional "switch parameter" (ie, a flag)
    [string] $user = $(if ($switchparam) { Read-Host -prompt "User"}) #prompt user for value if none provided
  )&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In the above example, if –switchparam is specified in the command, the $user parameter default expression will evaluate to true and prompt the user for a user name.&lt;/p&gt;
&lt;div style="margin: 0px; padding: 0px; display: inline; float: none;" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ade2b32e-3455-4465-81b5-b9b33c976bf1" class="wlWriterSmartContent"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/PowerShell" rel="tag"&gt;PowerShell&lt;/a&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/136822.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2009/12/08/powershell-smart-parameter-expressions.aspx</guid>
            <pubDate>Tue, 08 Dec 2009 06:49:53 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/136822.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2009/12/08/powershell-smart-parameter-expressions.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/136822.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/136822.aspx</trackback:ping>
        </item>
        <item>
            <title>PowerShell Command Line Emailer</title>
            <link>http://geekswithblogs.net/Lance/archive/2009/10/20/powershell-command-line-emailer.aspx</link>
            <description>&lt;p&gt;I’ve talked about this before, but it came up again today so I thought I’d do a quick post about it.  Here’s a function I use in my PowerShell profile that uses &lt;a title="NetCmdlets" href="http://www.nsoftware.com/powershell/"&gt;NetCmdlets&lt;/a&gt; to send quick “todo” emails:&lt;/p&gt;

&lt;div class="psscrollarea"&gt;
&lt;pre&gt;function todo($target="work", $msg) {&lt;br /&gt;  switch ($target)&lt;br /&gt;  {&lt;br /&gt;    "work" { $target = "lancer@nsoftware.com" }&lt;br /&gt;    "home" { $target = "lmrobins@gmail.com" }&lt;br /&gt;  }&lt;br /&gt;  send-email -from lancer@nsoftware.com -to $target -subject ("Todo: " + $msg) -message $msg -server 10.0.1.1&lt;br /&gt;}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;During the day, when I need to send myself a reminder, I can just say:&lt;/p&gt;
&lt;p&gt;PS&amp;gt;todo home “remember to buy apples”&lt;/p&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;p&gt;PS&amp;gt;todo work "schedule meeting with Mark and his team"&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;This is always faster than bringing up my email client, composing a new message and clicking send.  You’ll notice that my function uses the send-email function from &lt;a href="http://www.nsoftware.com/powershell/"&gt;NetCmdlets&lt;/a&gt;, but just substitute your own email code if necessary.&lt;/p&gt;
&lt;div style="PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; FLOAT: none; PADDING-TOP: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:ade2b32e-3455-4465-81b5-b9b33c976bf1" class="wlWriterEditableSmartContent"&gt;Technorati Tags: &lt;a rel="tag" href="http://technorati.com/tags/PowerShell"&gt;PowerShell&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/NetCmdlets"&gt;NetCmdlets&lt;/a&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/Lance/aggbug/135604.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Lance Robinson</dc:creator>
            <guid>http://geekswithblogs.net/Lance/archive/2009/10/20/powershell-command-line-emailer.aspx</guid>
            <pubDate>Tue, 20 Oct 2009 12:07:35 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/Lance/comments/135604.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/Lance/archive/2009/10/20/powershell-command-line-emailer.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/Lance/comments/commentRss/135604.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/Lance/services/trackbacks/135604.aspx</trackback:ping>
        </item>
    </channel>
</rss>
