This is a blog post on request. Someone commented on another post (Create Autopilot Profile Powershell) that they would like a script to create a Domain Join Profile in Intune via Powershell.

Some of you need to create more than 10 of these profiles. (Some even more than a 100!)

I thought that was interesting! So, I opened my VS Code to create the script.

Prerequisites

You need an account that has enough permissions in Microsoft Intune. Read more about it here.

The script

The script is more than 100 lines. So, I put the script in my GitHub account. This is the link.

You can run the script with the following example code:

$PolicyName = "Windows10_DomainJoin2"
$Assignment = "All Users"
$ComputernamePrefix = "Win10"
$ActiveDirectoryFQDN = "nielskok.tech"
$OUname = "OU=Demo,DC=NielsKok,DC=Tech"

.\DomainJoinProfile.ps1 -PolicyName $PolicyName -Assignment $Assignment -ComputerNamePrefix $ComputernamePrefix -ActiveDirectoryFQDN $ActiveDirectoryFQDN -OUName $OUname

I will explain the parameters below:

PolicyName –>This is the name that the profile gets in Intune (Displayname)

Assignment –> There are 3 options: “All Users”, “All Devices”, and “Custom group (Fill in Azure AD Group ID)”

ComputernamePrefix –> Prefix for the devices that will be domain joined. After that, a string of 10 random numbers is added to the name. You can change this in the script if you like.

ActiveDirectoryFQDN –> Fully qualified domain name for your Active Directory Domain

OUName –> Organizational Unit where you want to put the machines

Example Run

All Users:

All Devices:

Custom Group

6 thoughts on “Domain Join Profile Intune via Powershell”
  1. My goodness, that was fast 😉
    Thanks so much for this Niels – aside from the utility of the script itself, which is awesome, I think studying it will also give me a lof of insight for automating config profile creation.
    I will get cracking now testing this script 😉

      1. Tested your script now. Working perfectly for me. Combined with your other script it’s really going to speed this up for us. I found I can actually reduce the entire thing to one initial variable, which can be injected automatically when an OU is created in our on prem AD. That way we get a zero touch process for generating Autopilot templates.
        So again many thanks, looking much forward to further blogs from you ;). How to create a script for Graph will definitely be one I will read with interest !

Leave a Reply

Your email address will not be published.