Create custom Nano server 2016 VHD

Create nano server







I built this script so people easily can get a start and try their Nano server 2016 within a couple of minutes. I have only tried it with Windows server 2016 Technical preview 4. It is pretty straight forward the script launches a windows where you can name your server and check the functions you want, add the disk image och create the server:

1. Enter namne of VHD
2. Check the functions you want to add and press button add server, you can add multiple server if you want to.
3. Press button Add Disk Image to point out windows 2016 iso.
4. Press button create servers to start building VHDs.
5. Enter Administrator password
6. You ne VHD will be stored in C:\Temp_NanoServer

I have not tried all functions, hopefully they all work.

Check which servers have powershell remote enable

Sometimes you need to run a Powershell remote script on a big number of servers or computers. Powershell remoting can often fail and it can be all kinds of reasons of failing, powershell remoting is disabled, a firewall or two is blocking the connection or you don’t have the permission on the remote computer to enter a powershell remote session. I ended up in one of this scenarios the other day were I had local administrator permission on all the servers and an open firewall but still couldn’t enter a remote session on a bunch of servers. I put together this simple script that first collects all of our servers from the Active Directory and then creates an empty array to collect the result from the foreach-loop later in the script:

After that I take the result from the Get-ADComputers and and crunch it through a foreach-loop where I try to enter powershell remote sesssion with all the servers that I collected in the previous step . I use the ErrorAction parameter with the stop switch to get an terminating error. When I get an terminating error that is when Enter-PSSession fail, the code inside the catch braces will run and there I just add the server name to the array I created earlier:

When the script is done I will end up with all the failed servers in the $serversNoPsr variable.

Full script:

Exchange get all users and list names and which database they are located on

At work we sometimes get restore cases on mailboxes where the backup is located on tapes outside of the tape robot. We the have to restore all databases and then manually find which database the user is located on. This is very time consuming and to cut restore time and to make it easier for the technician doing the restore I came up with this script that will export which database the user is located on the specific date. with this information the technician will only have to restore a single database. The script will mail the result as an attachment to one of our function mailboxes and store it locally on the server where the script will run as a scheduled task.

Progress bar Example




When working with large loops that take a lot of time it’s nice to know that something happens and the script is making progress. You can use write-host $item to write something that is  unique in the loop or even better use the count method on the variable that you have stored the data you want to loop and then use an integral to count up. if you do that you can easily use the write-progress cmdlet to get a nice progress bar.

I often end up working with foreach  loops and here is an example how to use the write-progress in an foreach loop. In this example I use the status-parameter to get the xxx services out of 235 is done counter and the PercentComplete-paratmeter. I use an integral that I set to 0 in the beginning and then ad 1 in each foreach loop,in that way I can easily track how many of the 235 items that I have looped through. To get the percentage I need to divide the int every time with the total I got from the count method, in this case 235 and then multiply it with 100 to get the percent.


First help desk GUI tool

helpdeskDelivered my first GUI tool to our help desk today. They needed a tool to find out which users populated distribution groups and they also wanted to be able to export three different attributes to a csv. I did the GUI design in visual studio and used XAML because it looks a little nicer then the old windows forms. the application got real-time check against the Active directory as you type to check if the group exist and it doesn´t enable the list user(Lista användare) button until you type the name of a group that exist. When the listing is done you can choose which attributes to export. This is a 1.0 and it doesn’t handle nested groups, if they want that functionality or some other functionality in the future I will update this post.


Measure max log-size on multiple servers

I got a little fuzzy case of how much disk all our server event-logs consume. Since the purchaser is still on vacation and couldn’t answer any questions I put together a 0.1 version with the old get-eventlog commandlet, depending on meeting with the purchaser I might replace it with the get-winevent that is a little more powerfull. The text displayed to the user is in Swedish since I´m working against swedes. First the script collects all servers in the active directory. After that I built the function get-logs that first collect all event-logs and then calculates the size of all logs and add the size and servername in an pscustomobject variable, it also adds the servers log size to the global variable $total to get a total size from all servers. I then use the function in an foreach loop with all the collected servers as targets. In the end it send a pop-up window to the user asking if he/she wants to export the result to an CSV-file. If you are interested in what the Swedish sentences means I recommend

Change windows theme based on season

A couple of Sundays ago I was laying in the couch with a small hangover and my kids were watching cartoons I got an idea that I would like to have my theme and desktop wallpaper change with the weather season. Since I am Swedish I wanted the wallpapers to be from my home country. I found out that Microsoft had season themes with desktop pictures from Sweden on their homepage, so I could easily use Bits to download the themes. I made 5 variables with the days of each weather season stored in them and then used a switch to install the correct theme based on season. It worked like a charm and I scheduled a task on my main computer on each login so it will change theme as when season change. I also sync themes on my other computers that use Windows 8.1 and 10 so i get the correct season theme on all my computers.

Collect users with a certain attribute and clear the attribute.

Last week a college working with identity management needed a script to clear a dummy AD-attribute. All users that don´t have a telephone number needed a dummy phone number because of an external calendar system. This script collects all users with the telephoneNumber attribute 99999 in an variable and then exports the users in the variable with all their attributes before it clears the telephoneNumber attribute. We use it as an scheduled task.

Locate printer driver on multiple computers


A couple of weeks ago a bad printer driver where distributed to some of our clients. It was an universal driver so the impact was on nearly every printer of a specific brand and that brand  represents approximately fifty percent of our printers. We now needed to find out which computers had the faulty driver and to do so we searched every computer if it had a driver with the same driver version(do a get-printerdriver | select * and on property “driverversion” you will find a number) as the bad driver. Since not all of our 8000 clients are powered on or on our network we also exported all computers not answering on Test-Connection to a file that we can use later if we run the script again. After my college had run the script he ended up with two files, one with all computers with bad driver and one with computers not answering to test-connection.