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

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 😉
Nice! Maybe for the next blog. How to create a script for Graph.
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 !
Thanks mate!
Love reading that this helps you a lot!
Regards,
Niels
[…] Domain Join Profile Intune via Powershell […]
[…] Posts:Domain Join Profile Intune via PowershellIntune Assign Store Applications via […]
Hi Niels,
Many thanks for this, hope you don’t mind, but I edited your script so it runs a foreach statement based on an CSV import, here is the script if you or anyone needs it: https://github.com/durrante/Intune/tree/master/BulkCreateDomainJoinProfiles
Always nice to see!
Thanks,
Niels
Hey should i change parametrs in whole script or only in header?
$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
Best Regards
Hi Lukas,
You only need to change these variables:
$PolicyName = “Windows10_DomainJoin2”
$Assignment = “All Users”
$ComputernamePrefix = “Win10”
$ActiveDirectoryFQDN = “nielskok.tech”
$OUname = “OU=Demo,DC=NielsKok,DC=Tech”
After that, you can run the script.
Thanks,
Niels