Using Windows PowerShell to check for users on a remote machine and then restart it

Recently I had the Remote desktop services stop responding while I was working out of the office. Since I didn’t really want to go in to reboot the machine I decided I would do it remotely.

Even though it was the weekend I decided that I better check no one else was on the machine doing anything. The following script can be used to see who is on a machine.

param (
    [string]$computername = "."

$explorerprocesses = @(Get-WmiObject -Query "Select * FROM Win32_Process WHERE Name='explorer.exe'" -ComputerName $computername -ErrorAction SilentlyContinue)
if ($explorerprocesses.Count -eq 0)
    "No explorer process found / Nobody interactively logged on"
} else {
    foreach ($i in $explorerprocesses)
        $Username = $i.GetOwner().User
        $Domain = $i.GetOwner().Domain
        $Domain + "\" + $Username + " logged on since: " + ($i.ConvertToDateTime($i.CreationDate))

Used as below:

.\UserLoggedOn.ps1 -computername "ComputerName"

Results similar to:

DOMAIN\ACCOUNT1 logged on since: 04/30/2017 12:39:09
DOMAIN\ACCOUNT2 logged on since: 04/30/2017 12:41:16


Once I was happy no one was doing anything important I used:

 Restart-Computer -computername "Computername" -force

-force forces restart when users are logged on.



I’m just rebuilding my site at the moment as I have moved the hosting from azure to google cloud. I’m going to put all my old posts back on here first and then I might actually start putting stuff on here again. It has been a long time (over three years) since I posted anything really, but that is how life is sometime.

Disable the Windows Firewall on an SBS domain when it is locked with group policy.

I needed to turn a firewall off as someone was installing an application that used web services and they were having issues. I thought NP and hoped onto the server on a domain admin account and disabled the firewalls the way I would on any other machine using command line:

netsh advfirewall set allprofiles state off
netsh advfirewall set allprofiles state on

You need to run the command line / powershell as administrator for this to work.

I checked the firewall and found the firewall was off for everything but the domain networks and it was greyed out so I couldn’t turn it off. Interesting. So I figured I’d need to change some policy somewhere.

To fix this you need to change your policy settings by going to the group policy manager by finding the “Windows SBS Client Policy” (I did this on the domain controller server / SBS server)

Right click and select edit. Once open find:
Computer Configuration -> Policies -> Administrative Templates -> Network -> Network Connections -> Windows Firewall -> Domain Profile -> Protect All Network connections
By default this is set to enabled. Setting to disabled will turn it off, setting to not configured allows administrators to enable or disable the firewall on the PC

Last thing, it can take up to an hour and a half for policy changes to be applied to workstations\additional servers. You might want to force this to happen right away.
Use the following command line, on the workstation\server you want to disable the firewall on:
gpupdate /force

And like magic the firewall will be off. Just be careful though as you will turn the firewall off on every machine connected to the domain if you aren’t careful.

SharePoint Update Causes Event log Errors

On installing a new server and all the updates the following was found throughout he Application event logs.

The mount operation for the gatherer application has failed because the schema version of the search administration database is less than the minimum backwards compatibility schema version supported for this gatherer application. The database might not have been upgraded.

It appears that one of the updated required some manual intervention. The link below details what you need to do.

On doing this I started getting errors in the System Event log:
The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID
to the user BWEB\spsearch SID (S-1-5-21-26759078-436902130-1702569824-1161) from address LocalHost (Using LRPC). This security permission can be modified using the Component Services administrative tool.

This turns out to be related to permission for the “Storage Reports Service”.

Change Component Service Owner and Permission

In the DCOM Config dialog box, you noticed that the settings are grayed out. In order to enable those settings, perform the following registry modification.
1.Open Registry Editor by typing “regedit.exe” in Start > Run.
2.Navigate and select the key “[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\AppID\{35B4B29E-0A6B-4ED7-B0A1-117BF912F497}]”
3.Right click and select Permissions.
4.In the popup windows, click Advanced.
5.In the Advanced Security Settings windows, select Owner tab and change the owner to Administrators. Click OK to close the window.
6.In the Permissions screen, select Administrators and check Full Control. Click OK to close the screen.
7.Close the registry editor.

In order to change the permission settings, perform the following steps.
1.Open Component Service by clicking Start > Administrative Tools > Component Services.
2.Navigate and expand the node Component Services > Computers > My Computer > DCOM Config.
3.Right Click the sub node “35B4B29E-0A6B-4ED7-B0A1-117BF912F497” or “Storage Reports Service” and select “Properties”.
4.On the Properties dialog box, select Security tab.
5.In the Launch and Activation Permissions section in Security tab, select Customize option and click Edit.
6.In the popup window, add the farm admin user account and check Local Launch and Local Activation permissions. The screen should look like this.

All should be well again.

Excluding files in Mercurial – Kiln for use with Visual Studio

After working in environments where there was source control and task tracking for so long there was just no way I could start building applications or writing code without having such systems in place. So the first thing I did when I started working in my current position was look at Task/bug tracking software and source control software. In the end I decided on Fogbugz & Kiln by Fog Creek Software. I went this direction as I like the fact that we could have them host everything and it was easy to support different development enviroments. If I was only developing with .net I think I would have likely gone with locally hosted Team Foundation Server.

Anyway I’m now doing some .net dev work and thought I would mention a few things I’ve found related to excluding files with Mercurial.

Too exclude files you create a .hgignore file. This should be linked in your mercurial.ini file. More about that later though.

First off windows is a bit of a pain and dislikes files that start with a a period ‘.’ so to create the file you may need to do something along the lines of the following:

1. cd to/my/repo
2. notepad .hgignore Notepad.exe opens and asks if you want to create the file. Say yes.
3. Add something to it:
4. Save

I would suggest you use the follow in your .htignore file it covers C#, C++ and Visual Studio development:

syntax: glob

* - [Cc]opy

Finally to make this file work with all your repositories you should link it in the [ui] section of your mercurial.ini file. This file is located in your user profile folder.

How do I configure Mercurial to use environment variables in mercurial.ini

To do this I modify the [ui] section of my Mercurial.ini (in my home path) to include:

ignore = ~/.hgignore

This appears to work for all version of windows and elsewhere.

Under windows 7+ you can use

ignore = %USERPROFILE%/.hgignore

Both of these should work for command line and tortoiseHG.

That is about all there is to it.

WCF Data Services – Debugging

I have been building some data services that are used to connect too Oracle data sources. Everything worked fine within VS 2010 but on pushing my service to IIS locally and remotely I was getting error 500’s. I managed to solve the issues locally without to much trouble but on the remote server I really couldn’t for the life of me see what was going on. By default there was really very little in the way of debugging information.


My First issue was error 500’s with no real logging. To find out what is happening here I used tracing. If you add the following to your web.config you will get some nice trace information:

<source name="System.ServiceModel"
switchValue="Information, ActivityTracing"
<add name="traceListener"
initializeData= "c:\log\Traces.svclog" />

MS info on this can be found here:

Then use the trace tool to look at the results:


I was running Windows Server 2008 64bit but the data source from Oracle for odata only appears to be available in 32bit and that is what I installed. I was getting an error 500. To fix this you need to set your App Pool to support 32bit executables. To enable this in IIS right click your app pool and under “Advanced Settings” set Enable 32-Big Applications to True. This fixed my error 500.


I was calling my WCF Data Service and getting a NotSupportedException with an InnerException of “An error occured while processing this request” there was no other information provided. I had no idea why this was happening, I needed to know more! After a lot of searching the net I found this setting:

public static void InitializeService(DataServiceConfiguration config)
config.UseVerboseErrors = true;

Building and deploying with this enabled gave me a nice error with the inner exception exposed.


ORA-12154: TNS:could not resolve the connect identifier specified

This doesn’t seem like much, and there are HEAPS of articles where it pops up but nothing I could find told me how to fix it. Until I came across this:
ORA-12154: TNS:could not resolve the connect identifier specified

It basically says copy your data connection configurations to your client folder. When I installed the VS Compoents and the Odata/ client it created a new home directory and the configurations files were not getting picked up from the server home. I copied these and everything started to work!
NOTE: I needed to restart Oracle and IIS for these new settings to take effect.

Small things often cause pain – So why can’t I create a variable inside a switch statement?

Sometimes the smallest things can cause you pain. I had a nice example of this today. I’m still new to Objective C and find something new everyday. Was using a switch statement and had what at the time seemed like an odd little issue. I couldn’t seem to create variables and call methods. The error message I was getting back really wasn’t that helpful. Turns out it was as simple as surrounding the case statement calls in curly brackets. See below:


case 2: 
    Alert *alert = [allAlerts objectAtIndex:indexPath.row];

    alertCell.textLabel.text =;//@"Date";
    alertCell.detailTextLabel.text = @"Alert Message";
    return alertCell;


case 2: {
    Alert *alert = [allAlerts objectAtIndex:indexPath.row];

    alertCell.textLabel.text =;//@"Date";
    alertCell.detailTextLabel.text = @"Alert Message";
    return alertCell;
} break;

Yup all I need was those two curly brackets 😉 Now if only Xcode could have told me that!  Yeah I know this isn’t a big thing, just think it’s funny how the small things can be such a pain at times and how knowing the syntax of a language really can be an advantage at times. I guess the moral of the story is that small things really do matter.


Adding formatted text to iOS applications – UIWebView, HTML from a string.

You would think that this would be easy as can be? Surly there must be a text box with formatting built in?? Apparently that is not the case. You can obviously use core graphics and render some text any way you like, but that just didn’t fit into what I was doing. The best method I could find was to just use UIWebView.

This is really rather simple. Below are the steps you need to take to use this with text:

  1. In UI builder add a UIWebView object to your view
  2. Add an Outlet to your header file:
    @property (nonatomic, retain) IBOutlet UIWebView *formattedTextView;
  3. Add a property or variable to store the HTMl:
    @property (nonatomic, copy) NSString *theHTML;
  4. Synthesize the properties and of course release them in the dealloc method:
    @synthesize theHTML = _theHTML;
    @synthesize formattedTextView = _formattedTextView;
    [_theHTML release];
    [_FormattedTextView release];
  5. In the implementation of the view add the html and assign it to the control, in my case I did this in didFinishLaunchingWithOptions you simply use loadHTMLString with a nil base URL:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    self.theHTML = @"<html> \
    <head> \
    </head> \
    <body> \
    <p>Hello World<p> \
    [self.formattedTextView loadHTMLString:self.theHTML baseURL:nil];
    // Override point for customization after application launch.
    [self.window makeKeyAndVisible];
    return YES;


Not a hell of a lot to it really.

Would love to hear from anyone who knows of a better way to do this 😉


Pop3 mail connector email size limit on SBS 2008 and Exchange 2007

I have been doing some networky type guf lately and on moving all our mail onto a local exchange server I discovered a wonderful little feature where you can connect to pop accounts to grab email and feed it into Exchange accounts. This is great because a few of the users in the office have historical email accounts and this makes checking them pretty much transparent to them.

The only issue is that after a few days I found I was getting errors relating to email size. See the following:

Event 210, which is just a oversized email error pretty much.

It didn’t take too long to find out how to fix this. It is simply related to the email size defaults on SBS2008. The default email size for SBS2008 is 10MB. Use the following command in the exchange shell you can see what your max sizes are:

get-receiveconnector | select identity,maxmessagesize

The screenshot below shows my current results:

The next step is to increase these limits, I have obviously already done so here. The following command will do just that:

set-receiveconnector "<identy>" -maxmessagesize 20MB
Obviously you can make them whatever size you want. I increased them all, but for the pop account issue you onlye really need to increase the “Windows SBS Fax Sharepoint Receive <server name>” one.

Web Performance Tests – VS 2010 Crashing – Webtest Results Viewer

I’ve been doing a bit of work on Automated testing at work lately. As part of this I have been writing some custom web test plugins for creating data on the fly. Some pretty cool stuff can be done with these things.

Only issue is that I was getting some really annoying crashes. I couldn’t figure out what it was since it would crash VS with no errors. Turns out there is a bug in the webtest results viewer integrated into devenv.exe, this can crash when the very useful and seemingly innocent WebTest instance method AddCommentToResult() is used.

On the positive side it appears that this is fixed in VS 2010 SP1 – Link below

More to come on Automated testing soon…..