Sunday, 29 June 2014

Debian Screen Resolution when Hyper-V Guest

So I had a need to create a virtual machine on my laptop running Debian Jessie (Testing).   After the installation the screen resolution was limited to 1152x846.   This is a limit within Hyper-V.

I don't know why it took me a number of hours to find the fix for this but I found how to set the resolution on a blog called Random.GetNewEntry().

What is interesting about the fix is that it doesn't involve configuring X Windows. It is a simple change to the GRUB launch command.

I am keeping a copy of the changes needed here for my own reference, but 100 internets go to the owner of the blog.

  1. Edit the grub configuration file, for example:
    sudo vi /etc/default/grub
     
  2. Find the line starting with GRUB_CMDLINE_LINUX_DEFAULT, and add "video=hyperv_fb:1680x1050" (or your custom resolution) in between the quotes. For example: 
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash video=hyperv_fb:1680x1050"
  3. Save and exit 
  4. Run 
    sudo update-grub
  5. Restart your computer


Monday, 13 January 2014

Delete Windows Driver Packages

Today I had a need to remove a driver from Windows 7 x64 on a Syspreped Operating System.
As it turned it is it very easy to do thanks to a built-in tool called pnputil.exe.

Simply run pnputil.exe -e to get a list of third party drivers.   I piped the output of the command into a text file with pnputil.exe -e > pnputil.txt

Then search the new text file for the driver you need to delete.

Lastly, delete the driver package with this command pnputil.exe -d oem1234.inf
You will have to supply the correct file name for the above command to work.

This is all documented on TechNet here;
http://technet.microsoft.com/en-us/library/cc730875.aspx


Thursday, 28 November 2013

GIP the best PowerShell alias

I recently discovered the PowerShell alias GIP which runs the Get-NetIPConfiguration cmdlet.
This is the new ipconfig for PowerShell.
Here is the example for the straight gip command.



Here is gip with the -detailed option shortened to -det.


Isn't that great!
It might not be THE BEST PowerShell alias, but it is up there.   I think GCM would take that crown.

[Update] I just did a search and found a TechNet blog article about GIP and also TNC. TNC is an alias for Test-NetConnection and looks like a great alias also.   Read the article New Networking Diagnostics.


Thursday, 14 November 2013

Remove SkyDrive and Homegroup from Windows 8.1 File Explorer

Today I got sick of scrolling past SkyDrive and Homegroup nodes in the left pane of File Explorer in Windows 8.1.   I did a search and found a good post on Lifehacker and another post from a forum on how to remove them from the Explorer window.

Removing SkyDrive

I am adding the details here for my own reference but here is the link to the article from Lifehacker titled How to Get Rid of SkyDrive in Windows 8.1 Explorer.

The root of the change is to set a registry key called Attributes to a value of 0.   There is one problem though. The parent key called ShellFolder does not give read/write permissions to user accounts.   You will need to take ownership of the ShellFolder key and give your user account read/write permissions to change the Attributes value.

The key of interest is
HKEY_CLASSES_ROOT\CLSID\{8E74D236-7F35-4720-B138-1FED0B85EA75}\ShellFolder



Removing Homegroup

This one is a little easier.   Make sure you are not a member of any Homegroups and then disable two Homegroup related services in the services.msc utility.

The services are;

  • Homegroup Listener
  • Homegroup Provider

After you have made the above changes simply reboot the machine and the explorer windows will look like this;


Ah, that's better. No SkyDrive or Homegroup tree nodes.


Friday, 25 October 2013

Installing Harp on Debian Jessie

I recently came across the new open source web server called Harp.
Here is the description from the Harp website;


What is Harp?

Harp is a zero-configuration web server that is used to serve static assets. It has a built in asset pipeline for serving .jade, .markdown, .ejs, .coffee, .less, .styl as .html, .css, and .js. Harp supports a template agnostic layout/partial system and metadata for dynamically building files.


I thought I would take Harp for a drive around the block and decided to install it on a Debian Jessie virtual machine.
The installation process is rather easy except for one issue due to the Node.js package.

Here is the process to install Harp.

Firstly there are some prerequisites to get Harp installed being Node.js and npm, the package manager for Node.   I decided to install Node and npm using the Debian package repositories with these commands.

apt-get update
apt-get install nodejs npm

Once Node is installed, you can install Harp using the Node package manager.

npm install harp -g

The -g switch in the above command tells the package manager to make the Harp install global rather than a local directory install.

Harp is now installed and everything should be ready to go!   There is a problem though.   If you run the following command.

harp --version

You will get an error which is very misleading.

/usr/bin/env: node: No such file or directory

You can be forgiven for thinking that the harp binary was not found.   This is not the case.   The problem here is Harp is trying to call Node.js by using the command 'node' while on a Debian system the Node command is 'nodejs'.

This is easy to fix with the following symbolic link.   Simply run this command.

ln -s /usr/bin/nodejs /usr/bin/node

Now if you run Harp everything works as expected.

harp --version
0.9.4

All that is left is to follow the instructions on getting started to use the Harp web server.


Wednesday, 16 October 2013

A PowerShell Script to Warm Up or Wake Up SharePoint 2013

I was discussing SharePoint warm up solutions with some colleagues today and reviewed some of the solutions on the web.

The reason SharePoint needs warming up is because the first time a page is accessed in SharePoint the Just-In-Time compiler creates native images of the ASP.NET code within SharePoint.   Unfortunately this compilation needs to be carried out once a day due to the recycling of the Internet Information Services (IIS) World Wide Web Worker Processes (w3wp.exe) that host the SharePoint applications.

I decided to try my hand at writing one in PowerShell. Here is a simple solution.

Access the Gist here: https://gist.github.com/grantcarthew/7000687

Tuesday, 15 October 2013

A Telnet Client written in PowerShell

A little while ago I started writing a telnet client in Microsoft's PowerShell.   After it sat unfinished for a time I finally got around to improving it with multiple threads and cleaning it up.   It now works well so I decided to post about it.

Why would I write a telnet client in PowerShell?   Just for fun mainly.   It has been a good project to learn some more about PowerShell and may be of use for automating the configuration of Cisco routers and switches or running scripts on other servers.

The most interesting thing I learned as I worked through the project was about how to get PowerShell to support multiple threads.   Using the low level .NET Framework System.Net.Sockets.Socket class added to the complexity.

To start off with I created the telnet client using a "while" loop that ran continuously and caused the script to use up 20% of the CPU while doing nothing.   I couldn't fix this with a sleep timer because it made the client unresponsive.   The problem was I needed to respond asynchronously to reception of data through the TCP connection, and respond to user input at the console.   Very easy to do with C#, but in PowerShell?

To implement the reception and transmission of data at the same time asynchronously I started by trying to use the Asynchronous Programming Model used in the .NET Framework.   This is a little tricky because the tread pool used in PowerShell is different to the thread pool used in .NET.   I did find a way of using the async callback methods with PowerShell from a blog post by Oisin Greham.   I still had issues trying to get this to work though.

I gave up on using the async methods of the Socket class and started looking for alternatives.   It would have been nice to use the Register-ObjectEvent cmdlet and other event cmdlets but the Socket class does not have any publicly visible events to consume.

I briefly looked at the PowerShell Jobs cmdlets, but they didn't work well for this application because they use the remoting subsystem which serializes objects when they are passed between jobs.   This means passing an object by reference is not possible and I need a reference to the connected Socket.   That's when I came across the concept of creating a new PowerShell object using [PowerShell]::Create().

When [PowerShell]::Create() is called from a PowerShell script or console, a new instance of PowerShell with an empty pipeline is returned for you to make dance and sing any way you like.   The beauty of this new PowerShell object is you can pass objects by reference meaning I could pass the connected Socket.

So now I have two threads to use in my PowerShell telnet client.   The main PowerShell process creates a child PowerShell process and initiates it with a script to receive data from the socket.   After initiating the child a "while" loop is used with a blocking call to the $Host.UI.RawUI.ReadKey() method to wait for user input.

Rather than explain the code in any more detail, I will let the code do the talking.   If you want to use this code use the Gist link: https://gist.github.com/grantcarthew/6985142