[英]How to Add user in Active directory using Powershell
I am new to powershell and trying to add user in active directory using powershell, but for some reason I cannot tab complete on New-Ad for active directory, I have tried on windows 7 client with admin right also on DC itself. 我是Powershell的新手,并尝试使用Powershell在活动目录中添加用户,但由于某些原因,我无法在Active Directory的New-Ad上完成制表符的操作,因此我尝试在Windows 7客户端上同时在DC本身上以管理员身份进行尝试。 Can some one please help also what would be the code to do that? 有人可以帮忙吗,这样做的代码是什么?
Apologies non of the code is formatted nicely and only has terse comments. 不好意思的代码格式很好,只有简短的注释。 I hope it helps though. 我希望这会有所帮助。
The code below assumes you're on a non-DC server. 下面的代码假定您使用的是非DC服务器。 Not sure if this will work on a client machine, like Windows 7. 不知道这是否可以在客户端计算机上运行,例如Windows 7。
Import the server manager module and add in remote AD features... 导入服务器管理器模块并添加远程AD功能...
# import the server manager
Import-Module ServerManager
#add in remote AD features
Add-WindowsFeature RSAT-AD-powerShell,RSAT-AD-AdminCenter
#list PS providers (one of which should be ActiveDirectory)
Get-PSProvider
...this should give you intellisense, assuming you're on a version of PowerShell that has intellisense. ...这应该给您带来智能感知的能力,假设您使用的是具有智能感知功能的PowerShell。
To create a new user... 要创建新用户...
#create a new user
New-ADUser –Name "John Smith" –SamAccountName "john.smith" –Description "Sales Manager" –Department "Sales" –EmployeeID "45896" –Path "ou=users,ou=sales,dc=test,dc=local" –Enabled $true
Some other code that I scribbled down electronically, when I needed to create and explore AD users. 当我需要创建和浏览AD用户时,我会用电子方式编写其他一些代码。
#set location to AD
cd AD:
#list available options
dir
#explore the domain (replace DCNAME with domain)
cd 'DC=DCNAME,DC=local'
#back up
cd ..
#explore users (replace DCNAME with domain)
cd 'CN=Users,DC=DCNAME,DC=local'
#look at a user
Get-ItemProperty -Path "CN=Test ADUser1"
#find specific user
Get-ADUser "TestADUser10"
#find wildcard
Get-ADUser -LDAPFilter "(SamAccountName=*Test*)"
#get help on the aduser command
Get-Help Get-ADUser -Full
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.