Way back in the day - circa 2007 or 2008 I had a website that included some sample code and snippets that demonstrated things I’d learned at the time.
The content isn’t really that valuable any longer, but there are some nifty things.
Reproduced below (thanks to the Internet Archive, wayback machine is the content from two different versions of this page.
2009 and Earlier
Powershell Scripts
Some fun/interesting powershell scripts.
-
A tool to remove projects from a generated msbuild .proj file. Described elsewhere.
-
Guess the number of skittles!
-
I like having right click context menus in my explorer for opening a command prompt, or a powershell prompt, and starting in the folder I right clicked on. I wrote a powershell script to automatically add these items for me if they don’t already exist. :)
-
SysInternals provides many very useful tools. I recommend them highly; Microsoft thought so much of them that they bought them :). I’ve found it hard to accept their Pop-up Eula window when running tools like junction.exe, or handle.exe in a remote/automated environment, so I wrote a little powershell utility to accept the eula. To use the function, just pass in the name of the SysInternals utility that you want to accept the eula for in the -Program parameter. The default is “Junction”.
2010 Version
Powershell
I found a really weird bug/feature in powershell.
I couldn’t figure out why I was getting errors like:
Object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not legal or not in the correct sequence.
This is likely caused by a user-specified "format-list" command which is conflicting with the default formatting.
--->
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
--- End of inner exception stack trace ---
at System.Management.Automation.Internal.PipelineProcessor.DoStepItems(Object input, Hashtable errorResults, Boolean enumerate)
at System.Management.Automation.Internal.PipelineProcessor.Step(Object input)
at Microsoft.PowerShell.Commands.Internal.Format.CommandWrapper.Process(Object o)
at Microsoft.PowerShell.Commands.Internal.Format.SubPipelineManager.Process(PSObject so)
at Microsoft.PowerShell.Commands.Internal.Format.OutputManagerInner.ProcessRecord()
at Microsoft.PowerShell.Commands.Internal.Format.FrontEndCommandBase.ProcessRecord()
at System.Management.Automation.Cmdlet.DoProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
out-lineoutput : Object of type "Microsoft.PowerShell.Commands.Internal.Format.FormatStartData" is not legal or not in the correct sequence.
This is likely caused by a user-specified "format-list" command which is conflicting with the default formatting.
After some googling, I found an answer written by Don Jones in a forum.
Aparrently, the semicolon does not terminate a pipeline, so any code that appears after the semicolon is treated as part of the pipeline, which ultimately gets piped implicitly to Out-Default, which sometimes doesn’t know how to handle the output, causing this error.