howto://dump a list of users with email address and upn

I needed to dump a list of all users in a forest so that I could compare their UPN to their email address. I came up with this PS command that will connect to a GC, enumerate all users in the forest, and output a CSV that lists their displayname, emailAddress, and UPN. It will skip users with blank email or display, or accounts that are disabled.

The scriptlet assumes whoever runs it has administrative rights, and has the RSAT tools for AD installed on the machine they are using so the AD module exists. It doesn’t require anything else.

import-module activedirectory

get-aduser -filter {(EmailAddress -like “*”) -and (DisplayName -like “*”) -and (Enabled “True”)} -searchscope subtree -searchbase ‘dc=yourdomain,dc=tld‘ -properties DisplayName, EmailAddress, UserPrincipalName, proxyAddresses -server yourgc.yourdomain.tld:3268 | select-object displayname, emailaddress, userprincipalname | export-csv c:\scratch\users.csv

Make sure you change the variables in italics to match your environment. Hope this helps someone out.

Make bginfo a standard part of your Windows server deployments

If you are like most Windows admin’s, you find yourself accessing the console of various servers throughout the day. If you are using an rdp client like mstsc, or rdesktop, you may have several remote sessions open at the same time. And unless you just went through a major hardware refresh, you probably have a variety of different hardware platforms in production. If you are running multi-homed servers, or servers that for some reason cannot reliably resolve all required names through DNS, you probably have static route entries, and either a HOSTS file, an LMHOSTS file, or both, in use on your system. If you are like me, it gets kind of confusing trying to keep track of each system that you are on, and you might have wasted some time trying to troubleshoot a connectivity problem before realising that there was a static route, or an out of date ip.addr in the local file. Over time, I have come to make bginfo a standard part of every Windows server I stand up, and if I have to spend more than five minutes on someone else’s server and expect that I’ll have to come back later, odds are I will add it to that server too.

This tool was developed by the geniuses at Sysinternals, and though they are now a part of Microsoft, is still one of the free tools available here. When run, this tool will take whatever wallpaper you have, and overlay text information such as the system hostname, ip.addr information, cpu, ram, free disk space, or free form text. You can control the font, size, and colour of the information, and the placement on the desktop, and when you update, you can update the active desktop, terminal sessions, and even the wallpaper before login.

Here is a screenshot from one of my servers.

It is an ISA server, so there are both static routes, and the use of a HOSTS file. You can see that I feature that information prominently at the top of the page, along with the following standard information: hostname, boot time, ip.addr’s, cpu, ram, and free disk space.

As part of any server build, I use the following four files.
bginfo.exe-see the download link above
bginfo.cmd-a simple batch file to run at each login. You can also schedule it if you want more frequent updates without logging in. Here’s the contents of that file.
—start—
bginfo.exe c:\windows\config.bgi /timer:0
—-end—-
config.bgi
This is a binary file, so I cannot paste it here. The first time you run bginfo.exe, customise the basics as you want them, and save that as the default. This will create a %windir%\config.bgi file that you can copy to other hosts. The first time you run it, you will see all the available default fields. You can also define custom fields, or even insert images like the corporate logo if you want to.
bginfo.reg
This registry key can be imported into your registry, and sets up the RUN key so that the bginfo.cmd executes at each login. Here’s the contents of that file.
—start—

Windows Registry Editor Version 5.00 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run] 
"bginfo"="c:\\windows\\bginfo.cmd"

—-end—-

Copy the first three to %windir%, and just double-click the reg file to import it into your registry. Now, each time someone logs onto the server, the cmd file will run and update the information on the wallpaper. You can of course manually run it from the cmd line or start, run. You will probably want to play around with the colours of the text and background, as well as the fields that are displayed, until you find the right mix for you and any other admins on your team who will have to deal with your servers. Once you do, you will find this to be a great addition to your standard deployment, and find yourself wondering how you lived without it.

More information is available from Microsoft’s website at https://docs.microsoft.com/en-us/sysinternals/downloads/bginfo.