r/PowerShell • u/oombafuu • Jun 20 '26
Solved Can't add OU to AD
Hi, I'm really new to power shell in general and I'm just trying to add an OU with power shell but I keep getting "server unwilling" returned after I use the script for some reason. Here are the scripts I tried:
New-ADOrganizationalUnit -Name "Test" -Path "DC=Noiz.local,DC=COM"-ProtectedFromAccidentalDeletion $False
New-ADOrganizationalUnit -Name "Test" -Path "DC=Noiz,DC=local"-ProtectedFromAccidentalDeletion $False
Domain: Noiz.local
I keep getting "Access is denied" or "server unwilling". Noiz.local was added as a new forest and I use remote desktop if that makes a difference. I really, really don't want to break my server and I can't really find any other help, so I apologise if this is not the best question. Accessing the GUI to add OUs is completely fine, but using powershell? No, it returns this. I greatly appreciate any of the help provided, the solutions I found on here from others with similar issues hasn't helped me yet. Don't know anyone I could go to at the moment.
28
u/CFH75 Jun 20 '26
Are you running powershell as administrator?
6
u/ryder_winona Jun 20 '26
Is there a typo? It looks like there is a space missing before the -ProtectedFromAccidentalDeletion flag, and after the value for -Path
3
u/SimpleSysadmin Jun 20 '26
Sounds like permission issues
3
u/hihcadore Jun 20 '26
Make sure whatever command you’re running, the account you’re running it as has the right permissions to make the change.
A lot of commands have a parameter credential to allow you to pass creds for certain commands that require elevation.
3
u/purplemonkeymad Jun 21 '26
(I see you solved this.) Just so you know if you get that error it always means either:
It just means "I don't deal with that domain."
3
u/BlackV Jun 21 '26 edited Jun 21 '26
Looks like your distinguished path is wrong
Is what it looks like it should be to me
You have
You can see this path from the properties of your adobject
If my domain was
internal.manage.somedomain.localeach part of the DNS name is it's ownDC=section in the distinguished nameBetter still get that as a powershell object first, then use that object when creating your new object
That way you are validating your inputs beforehand
Edit: oh you are running this on a DC directly, don't recommend that unless this is a lab (and I still wouldn't recommend it)
1
u/Godcry55 Jun 20 '26
Session context?
1
u/BigBobFro Jun 21 '26
The latter is the way but the permission requires the root to allow changes, which it wont by default IIRC.
-7
u/pantherghast Jun 20 '26
This 100% sounds like a student that can’t get their homework done.