getting a web page with basic authentication using powershell

pont d'amour Getting a web page using PowerShell is pretty easy using Invoke-WebRequest. Getting a web page which is protected using basic authentication isn’t that much harder, but it took me a while to find out how to do that exactly as my initial searches didn’t turn up the right answers.

The trick is that you have to pass in a credential object when you make the call:

$result = Invoke-WebRequest http://foo.com -Credential $credential

That $credential object is something you have to create. If you don’t pass in an object, you’ll get a prompt btw, which might also be handy.
Creating the object is done like this:

$user = "john.doe"
$password = ConvertTo-SecureString "a_password" -AsPlaintext -Force
$credential = New-Object PSCredential($user, $password)

The PSCredential object is created and the username and a secure password string is passed into the constructor.

Putting the username and password in your script like this is a bad idea in a lot of cases, so you should really consider if this what you want to do. You can also use the Get-Credential cmdlet to ask the user for the username and password instead.
That way you keep this sensitive data out of your script and make it more resilient to change as well.
This is all it takes to ask for the credentials and set them into a variable you use later on:

$credential = Get-Credential

react.net clearscriptv8 compiler error

error
Here’s another one for the error message Googlers. Recently I ran into a nasty build error on TeamCity after adding React.NET Nuget packages to an ASP.NET MVC solution.
Locally everything built just find, but on TeamCity the build failed with the following error message when trying to compile the MVC views:

[AspNetCompiler] ASPNETCOMPILER error ASPCONFIG: Could not load file or assembly 'ClearScriptV8-32.DLL' or one of its dependencies. The specified module could not be found.

Normally you get this type of errors when an assembly can’t be found or isn’t copied to the bin folder for some reason.
In this case it turns out to be more or less the opposite case. The DLL is in the bin folder, but .NET should be ignoring it. Apparently ASP.NET tries to load all DLL files in the bin folder, which it should not do for the v8 ones, making it crash and burn.
The clue came from this StackOverflow post and this blog post. The fix in the blog post is a bit hacky but pointed me in the right direction. The SO answer to change the web.config is spot on.

So the trick is to exclude the offending binaries by listing them in the web.config compilation section:

<configuration>
    <system.diagnostics>
        <trace autoflush="true" />
    </system.diagnostics>
    <system.web>
        <compilation>
            <assemblies>
                <remove assembly="ClearScriptV8-64" />
                <remove assembly="ClearScriptV8-32" />
                <remove assembly="v8-ia32.dll" />
                <remove assembly="v8-x64.dll" />
                       ....
            </assemblies>
        </compilation>

This way the DLL’s are no longer automatically scanned, and your build can nicely go on compiling those MVC views without any trouble.

Photo by strange little woman on stream, cc-licensed.

class not registered error in PowerShell on commandlet

I ran into this weird COM component error trying to run a commandlet from an IIS administration module.

Retrieving the COM class factory for component with CLSID {688EEEE5-6A7E-422F-B2E1-6AF00DC944A6}
 failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_
 CLASSNOTREG)).

The module imported fine and I could list the available commandlets and get help on them. So everything seemed to be installed properly. It just turned out that I was running the command on the wrong platform.

Or to be more exact, I ran the command in a 32-bit mode Powershell instance while I should have been in a 64 bit version. The COM component that was called is a 64 bit one, and that didn’t sit well with the 32-bit Powershell instance.

So how do you see what version of Powershell you’re in? Find out by running this statement , which returns true or false:

[Environment]::Is64BitProcess

Now that you know what mode you’re in, try the other one. You should have both in your Start Menu, where the 32-bit one has (x86) appended to the name. In my case that did the trick.

Windows search results for Powershell shows all versions available of the PS shell.

 

erase free space on an SSD drive

DeleteAs you probably know (because you’re reading this post) Windows doesn’t really destroy a file when it is deleted. It merely removes the references in the file table so you don’t see it in on the file system anymore. But the file is still intact sitting there on your hard drive until some other file is written over it.
If you want to truly erase those files on a HDD drive you can use a number of tools to erase the free space on the drive. What these tools do is simply overwrite all free space with random data and thus effectively overwriting and destroying those deleted files still sitting intact in your free disk space.
Free tools that can do this are the command line Secure Delete tool from System Internals and the handy CCleaner (see the tools menu).

For an SSD drive however overwriting the free space with random data is bad for your drive. SSD’s have a limited number of times you can write data to their blocks. Using a random data overwrite tool, which can even end up do this multiple times, is just a bad idea.

Luckily everything is built into your SSD drive to do this automatically. It’s called the TRIM function and from Windows 7 on this is activated by default so normally you don’t have to do a thing to take advantage of this secure-delete feature.

However if you are like me then you want to be sure if this feature is activated.
On Windows, you can do this by opening a command prompt and entering the following command:

fsutil behavior query disabledeletenotify

If you get the following, your TRIM command is already active on Windows:

NTFS DisableDeleteNotify = 0

If this would return a value of 1, you can activate the TRIM function with this command:

fsutil behavior set DisableDeleteNotify 0

You can find more detailed instructions and information about activating the TRIM function here:
How to check if TRIM is enabled on your SSD and how to enable it
Why SSD TRIM support is so important and how to enable it

And then there’s always Google of course.

Photo by Delete, cc-licensed.

some end of year breakcore & jungle goodness

Here’s some things that have been sitting around in my inbox for too long. Time to get rid of them before the year ends and it starts becoming really embarrassing. :)

Synthamesk‘s Regression release on Kaometry records presents some very cinematic breakcore which makes me think of Venetian Snares’s “My Downfall” and “Rossz Csillag Allat Született” album. So basically that means you get some crazy chopped up breakbeats at hyper speed with some more chill classical instruments on top. Good stuff.

Another release I’ve been digging from the more drum’n’bass/jungle front, but still whack enough to be classified as somewhat breakcore is something from the Jigsore label. It’s the More Love EP from DJ L.A.B, featuring some classic chopped up jungle beats and heavy sine wave subs and ragga vocal bits. The choppage is pretty high level so it’s jungle for the advanced listener I guess. :) Also good stuff, so check it out.

Check out the Jigsore and Kaometry Soundcloud profiles if you’re wanting for more, cause there’s plenty.
Enjoy!

nian dub, dark and dubby dnb

UK-based collective Nian Dub is making some really cool dark and dubby drum’n’bass on EXE project.
I ran into them on Soundcloud and I recommend checkout out the EXE podcast Transmission 002 with Nian Dub and Semiotix linked below. There’s a bit of banter and chatting in there, but the tunes in between are awesome and you learn a thing or two about the lads.
If you like it without chatting there’s the EXE M004 mix featuring much of their music as well.

More cool stuff on the EXE project stream as well like an old favorite Aaron Spectre and Gore tech. Check it *does some of those wicked streetwise finger gesture shizzle and all*

disable flash and silverlight for safer surfing

Flash, Silverlight and (*gasp*) QuickTime plugins in your browser with the modern web are about as necessary as a horse whip is on a Tesla. Well I might be exaggerating a bit. There are still some useful sites out there that actually use these things. Intranet sites that run on IE only for example, or flaky game sites. But any self-respecting web developer has long ditched them in favor of fancy new HTML5 features.

So why would you still run these things in your favorite browser (Firefox right?) where they only take up extra memory and have a bunch of security problems that might end up causing you trouble. There have been enough exploits for the Flash plugin out there to be sure to actually update those plugins every time they ask for it. Which is about every week if I recall correctly.

Anyway, it’s better to turns those damn things off completely and only turn them on when you hit one of those web sites maintained by a dinosaur. That way you’re stopping that evil hacker from taking over your machine with his Flash exploit and you’re gaining some free performance along the way.

In Firefox you can turn those plugins off in your Tools menu, under Add-ons. Just select “Never activate” and you’ll be fine.
Switch it back to “Ask to Activate” if you’d need them again. That way they’ll never activate by accident either, if you forget to turn it back off.
On Chrome it’s a bit more elaborate, but the option “Let me choose when to run plugin content” sounds like a safe bet instead of having plugin code be ran willy-nilly.
IE? Ha! Who cares right?! For anything else, a properly aimed search query should find you the answer in no time.

Oh, and don’t forget to tweak your Flash security settings if you decide to keep it on after all.

The Firefox add-in screen with all plugins disabled. Just like it should be.