Script to join Domain

I'm trying to find a script that will allow me to join about 30 PC to the domain with powershell or other methods.
I try two different power shell scripts and I get this error ps1 cannot be loaded because running scripts is disabled on this system.
I try to add on the beginning of the script the following line but that did not help. Set-ExecutionPolicy Unrestricted.
I also use Kaseya to push scripts and I found a few scripts on txt format but they need to be under XML format so I convert a txt file to a xml file online but that did not work eider.
Any suggestion how I can achieve that by pushing a script to all PC's.
The script can be push and execute it by Kaseya VSA as long as the script works.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jose Gabriel Ortega CastroCEOCommented:
Ok, the errors are relative to the "Execution policy".
You can avoid that in multiple ways.

Here are 15 solutions:
Check the section:"Bypassing the PowerShell Execution Policy"

And here's a script to test:
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Setting the execution policy needs to be done outside of the script - if script execution is inhiited, the script cannot execute ;-).
You can run a PS script with  PowerShell -ExecutionPolicy Bypass -File 'C:\temp\script.ps1'
That should work with UNC paths too.
Shaun VermaakTechnical Specialist IVCommented:
VBS I wrote a decade ago
Option Explicit

On Error Resume Next

Const WIN9X_UPGRADE = 16

Dim objWMISvc
Dim colItems
Dim objItem
Dim strDomain
Dim strUser
Dim strPassword
Dim objNetwork
Dim strComputer
Dim objComputer
Dim objWMIService
Dim colOperatingSystems
Dim ObjOperatingSystem
Dim ReturnValue

Set objWMISvc = GetObject( "winmgmts:\\.\root\cimv2" )
Set colItems = objWMISvc.ExecQuery( "Select * from Win32_ComputerSystem", , 48 )
For Each objItem in colItems
    If objItem.PartOfDomain = True Then
    End If

strDomain = ""
strUser = "USERNAME"
strPassword = "Password1"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objNetwork = Nothing

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, NULL, JOIN_DOMAIN + ACCT_CREATE)

If ReturnValue = 0 Then
    Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate,(Shutdown)}!\\.\root\cimv2")
    Set colOperatingSystems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")
    For Each objOperatingSystem in colOperatingSystems
End If

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Webinar: Miercom Evaluates Wi-Fi Security

It's not just about Wi-Fi connectivity anymore. A wireless security breach can cost your business large amounts of time, trouble, and expense. Plus, hear first-hand from Miercom how WatchGuard's Wi-Fi security stacks up against the competition in our upcoming webinar!

infedonetworkAuthor Commented:
You are the man.
I just join a 2016 Server to the Domain with no problem by using Kaseya to push the VB script to the local machine that need to be join then execute the VB script via Kaseya. Once I put all the agents on all the PC I will try with a mix of windows 7 and 10 and I'm sure
I will join all the PC's in less than 2 minutes at the same time.
I will let you know how it work before the end of the week but it should be good
infedonetworkAuthor Commented:
Any Chance you have one that copy profiles? I did not even look at that situation yet but once I join all the pc's to the Domain I will have to copy all their files from the old profile to the new one. The easy but not so easy when is 30+ users is to go on the registry and rename the profile key of the new logon user of the new domain to the old key of the old profile but that involve the users first to logon and then me to go one by one on the registry to rename it since they are all different. I will look in to that very soon. I toght you may have something that will make it easy. Thank you for your help. It saved me few hours.
Shaun VermaakTechnical Specialist IVCommented:
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Note that ProfWiz free does not allow automation, and so it is a manual process. The paid version does.
Both can change the domain and take over the profile in one go.
infedonetworkAuthor Commented:
I know that. I already talk to them.
The Pro version is licence per tech and can be use more than once but even that does not allow automation. Has to be done one PC at the time.
The enterprise version allow all that but is 50 licences minimum and it can be use only for one project.
I'm looking at less expansive options for now. Is not that easy to get extra budget approved once it was already approved by the management.
I will keep looking if not I will do it via the registry one by one.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
The only pro of the manual registry approach is that you can do it remotely. I would just run ProfWiz on each machine, one by one. Remember that if you just remap the profile path via registry you also should change security (ACLs), as those are set to the original (local or other domain) profile owner.
Jose Gabriel Ortega CastroCEOCommented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.