What is my IP with a twist

I needed a tool, preferably a Powershell script, which could show my WAN IP address using alternate outgoing TCP ports, other then default http/s (80 & 443) when using websites like whatismyip.com.

The reason for this is that I use multiple WAN/VPN connections based on protocol for different purposes like web surfing uses one WAN/VPN connection and all other protocols uses the default WAN gateway.
I use pFsense Firewall and create firewall rules with an advanced settings and choose a Gateway other than the default like the example below:


For the tool, script or function I needed a site or service which responds to all different protocols. The one i found that were free, simple and used most ports in the TCP range, 1-65535, was portquiz.net.
The decision wasn’t hard, create a Powershell function that leverage the cmdlet Invoke-WebRequest to parse the content of the site and match against keywords using regular expressions.

This is the result:

DISCLAIMER: This script is published on “As Is” basis. I will not take any responsibility for any damage this script might do to your production or test server environment. Please ensure that you test this properly in a non-production environment before running or scheduling the script in a production environment.

Add Network Location/Drive using Powershell + Context Menu

I’ve received a request from one of my customers were they wanted a button or an application that could bypass the 255 max char file path length. Some inexperienced users often like the file tree structure so much that they name their folders with a complete essay which will override the max char file path length in a few seconds.

One way to overcome the file path length is to use mapped network drives, i.e. \\contoso.com\dfs\human_resources will be L:\. This method replaces any UNC network path with three letters instead of 33 in the example above.

Now you may start to wonder if this blog post is necessary. Use Group Policy Preference (Drive Maps) to map the UNC network path and manage every thing from a central location. Well of course this works when you have a few network shares and the users build their file tree structure on the width instead on the depth.
With our larger customers we try to use “Network Locations” using “GPP Shortcuts” instead of Drive Maps, the reasons are:

  1. Drive Maps only have a limited number of letters to use. 22 letters available (A,B, C and D excluded).
  2. Some Servicedesk conversations can be misinterpreted if you use the same drive letter for two or more locations.
  3. Application/system owners may use a drive letter for file based application search paths.
    Trust med this is an issue with slow WAN-links and when you want change or do some restructure in the file servers.
  4. Network Locations uses shortcuts to point to a UNC path. When accessed the shortcut translates to the full UNC path.

And of course with Network Locations there are some side effect and that are the max file path length issue when you have some users you like to write. So the reason that i started to write this script is for the end user to use when he or she encounters large file path lengths.

Here is the script:


An issue with this script is that the end users doesn’t use Powershell so I’ve had to come up with a way every user in the organization can bypass the long path file name with their favorite tool (the computer mouse). The first thing I did was to compile the script to executable file using Powershell Studio 2016. Now that I have the .exe file I need some way for the users to run the file using their mouse.

Context menu was the clear way to go.
Context Menu

The following registry settings are applied to accomplish the picture above:

One problem with the registry settings above is that C: is the SystemDrive disk.
This settings only apply to folders when you right click on them, according to the picture. You will not be able to right click in a folder to map to a network drive / location.

To insert the registry settings and the .exe application on the users computer I’ve created a .msi installer again using Powershell Studio 2016 so we can deploy everything either with GPO or ConfigMgr. I you are interested in the .exe or the .msi just write back to me or create your own using the source code above.

I hope this will help someone with network location or drive maps when using Powershell and a start with context menu while right clicking folders.

Powershell 4.0 – Try/Catch Exchange 2010 Bug?

I’ve been struggling some time now on why Powershell 4.0 are unable to “Catch” terminating errors when using Exchange 2010 Cmdlets.

When using a standard “Set-Mailbox” with Erroraction set to Stop using Powershell 3.0 the terminating error is validated by the “Try/Catch”-block:

Error with Set-Mailbox

When we use Powershell 4.0 with the same “Try/Catch”-block the result will be:

The operation couldn’t be performed because object ‘NoMailbox’ couldn’t be found on ‘DC01.contoso.com’.
+ CategoryInfo          : NotSpecified: (0:Int32) [Set-Mailbox], ManagementObjectNotFoundException
+ FullyQualifiedErrorId : 7780025A,Microsoft.Exchange.Management.RecipientTasks.SetMailbox
+ PSComputerName        : EX2010.contoso.com

A workaround for this is to use the $ErrorActionPreference variable:

Error with Set-Mailbox

Found an old thread on Technet touching this subject: Technet Forum
My speculation is whether this is a bug in the remote management of PowerShell 4.0 with Exchange 2010 Cmdlets or if it’s by design.
Either way the workaround works!

I haven’t tested this with Powershell 5.0. If you have please enlighten me if it works as it should like Powershell 3.0

First post

This blog is to share my thoughts and ideas for others where PowerShell is the main topic. I will try to use PowerShell for the discoveries where it’s possible.

Any questions or feedback regarding my posts, post a comment and I will answer as soon as possible.

A snippet from one of my first ISE-Snippets that I use.