Search a computer across all Domain Controllers

Search a computer across all Domain Controllers isn’t something I had to do in the past, but once, I had a little issue with a machine saying it was joined to a domain but it wasn’t in AD, even if the machine was joined 5 minutes earlier. I thought that perhaps it hit another Domain Controller and it was slowly replicating (this wasn’t the case). Still, out of curiosity I thought it’d be good to search a computer across all Domain Controllers; this is also a good option to see how fast the DCs are replicating content against each other.

Here’s the little script in Powershell:

Note: -ErrorAction Silently continue cannot be used with Get-ADComputer. To avoid getting errors every time the computer isn’t found on a certain Domain Controller I used Try/Catch. As you can see it tries (Try{}) to run the Get-ADComputer command, but if it returns an error, it’ll execute whatever is in Catch{}.

Read More

Logoff a user from multiple servers with powershell

This article is related to the article I recently wrote on how to identify what servers a user is logged on to with powershell. Actually we can re-use all of that script and just implement the logoff to it. We have a couple of ways to logoff a user from multiple server with pwoershell, based on the script located in the article I posted above:

  1. Utilise the .csv file, from the previous script, in a new script and run through it.
  2. Modify the script to add the log off functionality.

Both Options are really simple to follow and are both helpful since the first one will allow you to have a quick look through the list whilst the second one can be used when you’re sure you want to log everybody off!

1 – Utilise the .csv file, from the previous script, in a new script and run through it.

Remember that the script returned a .csv file composed of two columns per row: the hostname and the session ID of the user we want to log off. Since the previous script has done all of the work, all we need to do will be:

 

Easy! Pay attention though! If this is not your own account you’re working with, I would suggest you to add an extra check to make sure you’re logging off the right username. You could do something like this (we’re ignoring the Session ID the previous script caught):

 

Note: with the second script, you can use any list to perform this. You do not need the session ID as the script will find it by itself!

2 – Modify the script to add the log off functionality.

This is exactly the same script of the above article, it just has an extra line that will log off the user as well.

This is pretty much it on how to logoff a user from multiple servers with powershell.

(more…)

Read More

Identify what servers a user is logged on to with powershell

I am guilty to disconnect from a server and forget all about it and perhaps, months later, I find myself logged on that server. I built a quick script that helps me with this every now and then. Or perhaps you’re onto somebody else :) Let’s see how to identify what servers a user is logged on to with powershell!

First things first, you will need a list of servers (this will work on all clients as long as you have rights to query all of the machines).
I prefer to grab the list from Active Directory (you will need AD-RSAT tools with Powershell unless you run this on a Domain Controller) with the following command:

If you have already a simple list of hostnames stored in a text file, you can import it with:

Let’s see the whole script, it’s commented so that you can understand, but I’ll go through it:

So what’s happening is very simple:

  1. First I stated the username (just the username and not the domain etc).
  2. The csvOutput is the file that will be stored in C:\ which will contain a list of Hostames and Session IDs. In the script I also initialised it so that the first line will have Hostname,Session ID.
  3. I then grabbed the list of servers that are not disabled from Active Directory.
  4. In the foreach cycle, I went through each server in the Server List. For each server the script will:
    • Try to ping it (with just one request to make it faster).
    • Grab the session ID when the user matches. This is the most important line of the script. Also note that I used cmd /c so that I could use “2>NUL”. This is a nice workaround to avoid the script to output No User exists for *. This output is displayed every time quser hits a server with no users logged on to it.
    • Check if the Session ID exists, it makes sure it doesn’t contain “rdp” and that does not contain “console”. In my opinion we should avoid to grab a list of active sessions, especially if you want to use the csv file at a later stage to kill these sessions. Perhaps you’re logged off and you’re going to kill an active session from another user, losing all of his/her work!
    • If the Session ID respected the above criteria, then write to console something like User.Name is logged on SERVER01 with ID:5 and then it’ll also write SERVER01,5 in the CSV file.

(more…)

Read More

Excel won’t recognize dates

Help, Excel won’t recognize dates! This is frustrating sometimes, even when you right click on a cell and give it the correct format. In my case I have a script that exports the last logon dates from Active Directory and they’re formatted as DD/MM/YYYY. So for instance the 25th of March 2016 would be 25/03/2016. Very simple!

When trying to filter it, you’ll see them all in there and no Data Filtering is available:

lastlogon-unformatted

The funny thing is.. I also have a last password set field which is formatted the same way and that works just fine. I’m assuming the 01/01/1601 is driving Excel mad? :)

Either ways, this workaround I found seems to work all of the times:

  1. Select the whole column.
    • excel-select-column
  2. Click on Data on the top ribbon and then click Text to Columns.
    • excel-data-textTocolumns
  3. Select Delimited and click Next.
    • excel-textTocolumns-Delimited
  4. Now make sure that nothing is selected and click next.
    • excel-textTocolumns-delimiters
  5. Select Date and select DMY (or whatever format you have in your column) and then click Finish.
    • excel-textTocolumns-date-DMY

(more…)

Read More

SharePoint 2013 – The product requires Microsoft .NET Framework 4.5

The product requires Microsoft .NET Framework 4.5: I’ll go straight to the point, the issue is not .NET Framework 4.5 that is corrupted, but it’s .NET Framework 4.6 (or 4.6.1) that is installed and confuses SharePoint’s installer! It drove me insane and when I finally resolved it, I found an article from Microsoft about it. This was a funny error since when running the prerequisites, it was ok and it detected .NET 4.5 but it didn’t when it was going to install it.

All you have to do is uninstall .NET 4.6.1/4.6!

I had this issue whilst trying to install SharePoint 2013 – The product requires Microsoft .NET Framework 4.5.

the-product-requires-net-framework45

Bad news: when trying to search for .NET in the Add/Remove Programs (View Installed Updates), you won’t find it! You need to have the KB number for it. Good news: for .NET 4.6.1 it’s KB3102467.

So, go in View Installed Updates and Uninstall KB3102467.

uninstall-KB3102467-net461

Note: If you’re uninstalling 4.6.1, it’ll also uninstall 4.6! Now you can restart the server and you’ll be able to continue with your installation.

The first step I took to troubleshoot this issue was to verify what .NET version I had installed on my Windows Server 2012 R2 server. (more…)

Read More