Powershell and DHCP Domain Search Suffix Order

Hey there. The Finn is back after a long time, this time with a Domain Search Suffix Order issue. I ran into this issue at my new place of work where we have multiple platforms like Windows 10, MacOs and even Linux together with multiple domain names.
Traditionally you would just use a group policy to set the search lists on domain joined boxes. Problem solved, well not here because Linux and MacOs don’t do GPO’s. This pushed me to find an alternative that works cross-platform as well. Welcome to the DHCP option 119.
Windows Server DHCP does not include that option out-of-the-box, so you’ll have to add that manually prior to running the script.
Run dhcp mmc, right click on IPv4 under Servername and select “Set predefined options…”
Click Add, give it a descriptive name. Click on the “Array” checkbox, type in 119 in the Code-field and finish with “OK”.
Now you are ready to run my script below. Kudos to the original author for the hex-conversion. Made my day a lot easier. Why reinvent something that works?
My additions just gets all of your existing scopes and adds the 119 option values. Or you can also do a single scope at a time if needed. Remember to replicate your scopes if you are running in DHCP-failover mode since that is not done automatically.
Now all of your supported devices should work with this option. Not all OS’es actually request this option so your mileage might wary. Windows 10 as of 1809 should be fine. MacOs 10.6 (if memory serves) and Ubuntu from ages ago.
I hope you liked this post and got some use out of it. I am not sure how common this issue is but here is a verified solution for problem with distributing the Domain suffix search list to devices other than Windows.
set-option-119 rename to .ps1

Powershell for printer creation, with bonus feature.

Hey, the Finn here again with another random post.
A client reached out to me since they are in the process of switching print servers. They have a lot of printers, to say the least. They are all managed manually and they felt that they would like avoid the hassle of creating all the print queues manually on the new server. Powershell to the rescue!

They gave me a list with desired things that the script should do. I might have over delivered on that, but I like Powershell. It’s freaking awesome for so many things in Windows and beyond.

So, let’s have a look at what I did. Script full of comments for explanation ofc and split in regions for easy reading.

Since we will be dealing with installing printer ports, printers and DNS-records, I figured it might be a good idea to check that the script is “run as admin” or just end it right there.

Once that is out of the way we need to establish some customer specific variables such as the input file (CSV), the DNS server name, the zone in which to create the record and lastly the template printer that we want to use for custom settings.

After the initial variables now defined and checked by the script, we can move on to creating the actual functions that do stuff. So first we create the DNS-record.

This requires the DNSServer RSAT module to be installed on the machine running the script and you will not be able to run at all if that is missing since the script actually checks for that as well. However, this is really easy with Windows 10. Just run this powershell command: Add-WindowsCapability -Name Rsat.Dns.Tools~~~~ -Online and you are all set.

For the next portion of the script, we’ll need to create the network port on which the printer resides. We’ll get som in-data from the CSV that we utilize here. We’ll do a try/catch approach. Also, we will try to create the printer itself right after. Log to screen and file if something goes wrong.

Now, we have the printer created and ready to go. Now we will set the permissions on it from the template printer and also any other settings that are presented in XML from the originating printer.

That would be the last step in this excercise of the functions. Now, onto the trigger of the whole thing.

We do some basic checks before kicking things off. Making sure that there is a template printer, that we have the necessary powershell modules we need and also that the input-csv actually exists, before doing anything else.

Lastly we store the variables as arguments to send to the different functions and voilá, the script is done.

Feel free to comment all of my mistakes. Download file here.