Posts filed under ‘Uncategorized’

Converting PowerShell Scripts to HTML for Documentation

There are times when you want to publish a PowerShell script for documentation in a format where having it as HTML is the best option, such as in a blog posting.

I have used a couple of approaches for this.

One is to use an addin for PowerShell-ISE from Gary Lapointe which can be accessed from ISE’s Add-on’s menu and selecting the Add-ons Tools Website option or http://blog.falchionconsulting.com/index.php/2012/10/windows-powershell-v3-ise-copy-as-html-add-on/.

The other is to use PowerShell Studio from Sapien  https://www.sapien.com/software/powershell_studio.

It is handy to have the functionality added in to ISE but is is rather simplistic  as indenting is not maintained where as the Sapien tool, while creating more complex HTML, does produce a more readable result.  To see the difference, here are some renditions of a command I have for trimming strings:

The ISE addin

function ConvertTo-CCTrimmedString

{

[CmdletBinding()]

Param

(

[Parameter(ValueFromPipeLine = $True,

   ValueFromPipelineByPropertyName = $true)]

[String[]]$String

)

Begin

{

}

Process

{

foreach ($s in $String)

{

$processedString = ($S.Trim().Split($null) |

Where-Object { -not [String]::IsNullOrWhiteSpace($PSItem) }) -Join ” “

Write-Output $processedString

}

}

End

{

}

}

 

PowerShell Studio

function ConvertTo-CCTrimmedString
{
    [CmdletBinding()]
    Param
    (
        [Parameter(ValueFromPipeLine = $True,
                   ValueFromPipelineByPropertyName = $true)]
        [String[]]$String
    )
    Begin
    {
    }
    Process
    {
        foreach ($s in $String)
        {
            $processedString = ($S.Trim().Split($null) |
            Where-Object { -not [String]::IsNullOrWhiteSpace($PSItem) }) -Join " "
            Write-Output $processedString
        }
    }
    End
    {
    }
}

To explain the command, unlike the Trim() method on a string which only removes the leading and trailing spaces from the string, my command also reduces multiple instances of white space characters within the string (spaces, tabs, end of line markers etc) to a single space.

I have been using Sapien’s tools for over 16 years now and continue to be impressed with the quality and functionality of their tools.

February 21, 2017 at 2:11 pm Leave a comment

Where does PowerShell look for Modules

One of the great things from PowerShell 3 onwards is that you do not need to import modules to use them so long as they are stored in one of the locations that PowerShell will automatically look for them.  The directories that will be searched are listed in the environment variable PSModulePath.  A quick way to see the directories is:

(Get-Item env:PSModulePath).Value -Split “;”

On my computer, this returns:

C:\Users\Brent\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\
C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules\

As an aside to this, if you are part of an admin team you can put a UNC path in to this variable so it is possible to have a modules directory on a file share enabling the admin team to easily use and maintain an organisation module.

November 14, 2015 at 11:34 am 1 comment

NetComm NP206 Wireless Powerline Kit

I recently wanted to rearrange the WiFi access point in the house to get better overall coverage. Having decided that getting an extra phone point or trying to run cabling was going to be too difficult, I decided to try one of the Ethernet over the power options. I bought the NetComm NP206 units. One of the advantages of this option is that not only does it provide an ethernet connection so I could reposition the AP that I have, it includes a WiFi Access Point as well (802.11n which is better than the AP I already had.)

I plugged the two units in to the power points, they immediately connected to provide me with the ethernet link I needed to connect the ADSL modem to a better positioned Access Point. I plugged the AP I had in to one of the ethernet ports (there are two) and it all worked perfectly.

The I tried to connect to the built in AP. I could see the SSID, just as the manual described. The problem was that when I tried to connect to it it would not accept the password as described in the manual. On one of the devices that I have I received an invalid password message.

The solution – I downloaded the configuration utility, you can find it here:
http://www.netcomm.com.au/sm/drivers/np206

When I ran this, the password displayed for the AP was nothing like that described in the manual.

I reset the password (And the SSID while I was at it) and now have all my WiFi devices connecting to it.

The units seem to be working very well, and, with the exception (and quite a big one at that!) of the wrong password being described in the manual, it worked very easily.

November 13, 2011 at 4:29 pm 3 comments

C# MessageBox with Time Out

In an application that I am currently working on I need to have a MessageBox display a warning to users, but wanted it to close down after a time delay if the user did not click the OK button.  This is functionality that I had in the Shell.Popup in my VBScript work, so simply reused that functionality.

I did this by adding a reference to the IWshRuntimeLibrary by selecting Add reference and from the COM tab, selecting the Windows Script Host Object Model.

Then in my code simply put:

IWshRuntimeLibrary.WshShellClass wshShell = new IWshRuntimeLibrary.WshShellClass();

wshShell.Popup(“The Master version has shut down, so this instance needs to close as well.”, 10, “Master Instance of GhostCaster has closed”);

 

December 23, 2010 at 7:47 am Leave a comment

Medion Design USB Graphics Pad P46000

I recently purchased a graphics tablet from an Aldi’s supermarket, code  MD85637.  While the manual said that Vista did not need drivers installed, I did find it somewhat flakey on my 64 bit Vista.  I also tried to install the included drivers on a 64 bit XP install, with no success.  I checked the support site and emailed the support team.  While I got a quick response it was that there was no 64 bit support.  Further searching for support found a reference to the pad being a rebadged AIPTEK Hyperpen 12000U.  These drivers did not work and when I looked at the product description, it did not look like the same pad.  Further searching on the AIPTEK website did show that the pad I bought looked very much like their Slim Tablet 600U and the drivers for this tablet:

http://www.aiptek.eu/index.php?option=com_product&task=view&productid=135&Itemid=223

Seemd to work and the included software utilites also then installed and work.

July 31, 2008 at 1:35 am 13 comments

Deserializing a Dictionary Object

As part of an application I am maintaining user options in a Dictionary object that I can serialize to a user directory to survive the install of updated version of the appliation via Click Once.  Serializing was fine, when I tried to deserialize I received an error.

Thanks to a post by Miha Markic (http://cs.rthand.com/blogs/blog_with_righthand/archive/2005/08/06/92.aspx) I have the problem sorted.  The code is:

[Serializable]
public class Options : Dictionary<string, Object>
{
public static string DefaultFileName
{
get { return Util.DataDirectory + “options.bin”; }

}
private static Options tempOptions;

public Options()
: base()
{
}
public Options(SerializationInfo si, StreamingContext sc)
: base(si, sc)
{
}

public static Options Load()
{
return Load(DefaultFileName);
}
public static Options Load(string fileName)
{
Options tempOptions;
FileStream fs = new FileStream(fileName, FileMode.Open);
BinaryFormatter bf = new BinaryFormatter();
tempOptions = (Options)bf.Deserialize(fs);
fs.Close();
return tempOptions;
}

January 15, 2008 at 12:33 am 3 comments


Calendar

June 2017
M T W T F S S
« Feb    
 1234
567891011
12131415161718
19202122232425
2627282930  

Posts by Month

Posts by Category