Geeks With Blogs



Lance Robinson

Create Your Badge

Lance Robinson is a software engineer in Durham, Chapel Hill, Raleigh, and surrounding areas. More about Lance.


Lance's TextBox » About Me » My Resume »Twitter PowerShell Microsoft Windows PowerShell
Creating Team Foundation Work Items With PowerShell
Here is the simple function I added to my powershell profile: function create-tfstask ($desc) { tfpt workitem /new $workItemType /collection:$serverUrl /fields:"Title=$($desc);Ass... To=$assignee;AreaId=$areaId... } To find the AreaId and IterationId for your project/versions, just look at a bug you know is setup correctly: PS C:\> tfpt query /collection:http://3bs001vs... /wiql:"select AreaId,IterationId from workitems where ID = 879" Next I hooked this into ......

Posted On Wednesday, January 26, 2011 10:58 AM

PowerShell – Recycle All IIS App Pools
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. function Recycle-AppPools { param( [string] $server = "3bhs001", [int] $mode = 1, # ManagedPipelineModes: 0 = integrated, 1 = classic ) $iis = [adsi]"IIS://$server/W3SVC/... $iis.psbase.children | %{ $pool = [adsi]($_.psbase.path); if ($pool.AppPoolState -eq 2 -and $pool.ManagedPipelineMode -eq $mode) { # AppPoolStates: ......

Posted On Thursday, December 16, 2010 3:59 PM

PowerShelling from mobile devices
Marco Shaw is PowerShelling from his blackberry by running /n software's new PowerShell Remoting server along with the "Mobile SSH" client application for wireless handhelds . You can connect to the PowerShell Remoting client using any SSH tool, or even create your own custom client using a developer tool like IP*Works! S/Shell development toolkit. Technorati : Netcmdlets, PowerShell, nsoftware, ssh ......

Posted On Wednesday, June 6, 2007 12:58 PM

Managing IMAP access control permissions from Windows PowerShell
Setting access control lists on IMAP servers is a pain. But here's how you can do it very easily with the get/set-imap cmdlets included in NetCmdlets. Retrieve the access control list of my Inbox from the IMAP server, by specifying the -acl flag parameter: PS C:\> get-imap -server -user lance -password mypass -acl Mailbox Rights User ------- ------ ---- Inbox lrswipcda lance PS C:\> Now the access control list for a specific folder: PS C:\> get-imap -server -user lance -password ......

Posted On Thursday, May 31, 2007 5:06 PM

Upcoming conferences: Etech, MMS, Web 2.0

/n software will be at several upcoming conferences, including the O'Reilly Emerging Technology Conference, the Microsoft Management Summit, and the Web 2.0 Expo. If you will be there, stop by and say "Hi!".

Posted On Tuesday, March 20, 2007 9:26 AM

Quick PowerShell “Todo” Gmail Emailer
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: 1. Note the use of the $args variable to effectively allow the user to enter $msg parameter without quotes even if it contains whitespace. 2. In this particular example I’m sending the email through Gmail., port 587, SSL and authentication required. ......

Posted On Tuesday, October 26, 2010 1:27 PM

PowerShell TruncateAtWhitespace Function
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”. function TruncateAtWhitespace{ param( [string]$value, [int]$maxlength=200 ) $maxlength-=3; #allow for "..." suffix if ($value.Length -le $maxlength) { return ($value + "..."); } $closestwhitespaceindex = [int]$value.Substring(0, ......

Posted On Monday, August 16, 2010 3:30 PM

Exception setting "ThreadOptions" in SharePoint 2010 Management Shell
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: Exception setting "ThreadOptions": "This property cannot be changed after the Runspace has been opened." At C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONF IG\POWERSHELL\Registration\... char:48 ......

Posted On Wednesday, February 17, 2010 1:56 PM

PowerShell: Twitter Auto UN-follow
Anybody who uses Twitter has heard of auto-follow services for Twitter. 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 ......

Posted On Tuesday, January 12, 2010 1:06 PM

Program Files Environment Variable in PowerShell
Today I saw this on Twitter from Julie Blender (@#juneb_get_help): Need to reference the "ProgramFiles(x86)" environment variable in #PowerShell? Use ${env:ProgramFiles(x86)}. 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: First, I have a function in my testing profile called is64bit, that looks like this: function is64bit() { return ([IntPtr]::Size -eq 8) } Next, I have a get-programfilesdir ......

Posted On Tuesday, December 29, 2009 7:27 AM

10 PowerShell One Liners
Here are a few one-liners that use NetCmdlets. 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. Send email to a list of recipient addresses: import-csv users.csv | % { send-email -to $ -from -subject "Important Email" –message "Hello World!" -server } Show the access control list for a specific Exchange folder: get-imap -server $mymailserver -cred ......

Posted On Tuesday, December 29, 2009 4:36 AM

PowerShell: Smart Parameter Expressions
A while back I posted about how to mark a script parameter as required in PowerShell. 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. Let’s say you have the question: “Can I do <X> with a parameter?” The answer is probably “Yes”. :) Jim and an anonymous emailer both asked: Is there any way you can specify a parameter based on the value of another parameter? The answer is yes. You can put pretty ......

Posted On Tuesday, December 8, 2009 1:49 AM

PowerShell Command Line Emailer
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 NetCmdlets to send quick “todo” emails: function todo($target="work", $msg) { switch ($target) { "work" { $target = "" } "home" { $target = "" } } send-email -from -to $target -subject ("Todo: " + $msg) -message $msg -server} During the day, when I need to send myself a reminder, ......

Posted On Tuesday, October 20, 2009 8:07 AM

5 PowerShell Oneliners to Manage IMAP Permissions
You can manage user permissions in Exchange and other mail servers with the same commands by using the IMAP protocol instead of server-specific tools. Here is how! Jumping right in, these all use get-imap and set-imap from NetCmdlets: #1 – Get ACL Here’s a one-liner to get the ACL for a specific folder in an account. In this particular case, my main INBOX has a subfolder named RESUMES, and I want to see who has what permissions to this folder. PS C:\> get-imap -server $mymailserver -cred $mycred ......

Posted On Thursday, June 4, 2009 11:11 AM

Get the number of current SharePoint connections
Here is a PowerScript function to automate the process of getting/logging the current number of connections to a particular Web Server. It will tell you the number of connections for each site on the server, so you can see the number of SharePoint connections, SharePoint Central Admin connections, etc. Thanks to MOW and Lee Holmes for their examples of using the PerformanceCounter class in PowerShell. function Get-WebServiceConnections(){ $results = @{} $perfmon = new-object System.Diagnostics.Performa... ......

Posted On Wednesday, June 3, 2009 10:29 AM

Troubleshooting FTP connections with PowerShell
I find that helping people troubleshoot FTP connectivity issues is much easier if they have PowerShell installed. I can just have them run the NetCmdlets ftp cmdlets with the –debug switch, which displays a trail of information about the communication over the wire. In this way you can see every command send to the server and every response coming back from the server, including what ports a server is attempting to use for ftp data connections. Very often ftp transfer connectivity errors are the ......

Posted On Thursday, May 21, 2009 1:22 PM

Managing MS Exchange Remotely From Unix, Phone, Windows, etc.
Recently I saw a question come to my friend Spencer here at /n software about whether or not it was possible to use the Microsoft Exchange 2007 SP1 PowerShell cmdlets through the /n software PowerShell Server. The person wanted to be able to manage Exchange from a remote Unix machine. Of course, as I’ve mentioned before, it could be done from anywhere that supports SSH – like an Apple iPhone or a Blackberry. The PowerShell server uses impersonation - it impersonates the user that the SSH client authenticated ......

Posted On Wednesday, May 6, 2009 12:55 PM

PowerShellRSS Automatically Converts PSObjects to RSS Items
In a previous post, I talked about how PowerShellASP can be used to generate an RSS feed with PowerShell. Now I’ll show how the same feed can be generated more easily with PowerShellRSS. Again, the dir command in PowerShell (get-childitem) is used to get a listing of files to use as enclosures in the feed. # This example demonstrates how to generate an RSS feed from a call to the Get-ChildItem cmdlet (dir). # To tailor to your specific needs, set the following values: $mediadir = 'C:\Testing\media';$virtual... ......

Posted On Tuesday, May 5, 2009 5:42 PM

PowerShell Prompt inside SharePoint
Using the PowerShellToys PowerShellWebPart, I was able to insert a PowerShell command prompt inside my SharePoint page with only a few lines of code and some html. Here is the PowerShellWebPart template that I used: <div style="background-color:Dar... color:white; height:400px; width:650px"> <form method="GET" action="" enctype="multipart/form-dat... PS> <input type=text name="query" size="40" value="<%=$request['quer... /> <input type=submit value="Execute" /> ......

Posted On Tuesday, May 5, 2009 3:47 PM

New Toys for PowerShell!
At, you’ll find a bunch of new toys for PowerShell, including the first full release of PowerShellASP + free community license. The new toys? PowerShellADO, PowerShellPanel, PowerShellWebPart, and PowerShellRSS. Here’s a brief description of each, in my own words. For the official description and examples, check out PowerShellASP – write ASP pages with PowerShell scripting instead of vbscript. PowerShellADO – execute PowerShell cmdlets and return the results ......

Posted On Monday, May 4, 2009 5:00 PM

Copyright © Lance Robinson | Powered by: