简体   繁体   English

如何使用Powershell在Windows Server 2008 R2上管理本地用户帐户?

[英]How can I manage local useraccounts on windows server 2008 r2 with powershell?

I should create, activate and deactivate local user accounts on windows server 2008 r2 with powershell. 我应该使用Powershell在Windows Server 2008 R2上创建,激活和停用本地用户帐户。 I already do it with active directory, but I don't find the commands for local accounts. 我已经使用活动目录执行此操作,但是找不到用于本地帐户的命令。 Can anyone help me? 谁能帮我? Best regards. 最好的祝福。

Karl 卡尔

I'm sorry if I were not as accurate as I should be. 很抱歉,如果我没有达到应有的准确性。 I have to do it for the local user account on a member server, not on domain-controller. 我必须为成员服务器上的本地用户帐户而不是域控制器上的本地帐户执行此操作。

When you install Active Directory, it removes any local accounts. 安装Active Directory时,它将删除所有本地帐户。 This is intended. 这是有意的。

This question would be better suited for https://serverfault.com/ 这个问题更适合https://serverfault.com/

function create-account ([string]$accountName, [string]$accountDescription) {
$hostname = hostname
$comp = [adsi]"WinNT://$hostname"
$user = $comp.Create("User", $accountName)
$user.SetPassword("change,password.10")
$user.SetInfo()
$user.description = $accountDescription
$user.SetInfo()
$User.UserFlags[0] = $User.UserFlags[0] -bor 0×10000 #ADS_UF_DONT_EXPIRE_PASSWD flag is 0×10000
$user.SetInfo()

$objOU = [ADSI]"WinNT://$hostname/Administrators,group"
$objOU.add("WinNT://$hostname/$accountName")

$objOU = [ADSI]"WinNT://$hostname/Remote Desktop Users,group"
$objOU.add("WinNT://$hostname/$accountName")
}

create-account "testuser2" "Some Description"

Save thats as .ps1, edit info to suit and then run it. 将它们另存为.ps1,编辑信息以适合需要,然后运行它。

http://www.jrdata.se/2012/10/31/add-local-users-with-powershell/ http://www.jrdata.se/2012/10/31/add-local-users-with-powershell/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Windows Server 2008 R2上通过Powershell 4.0创建计划任务? - How can I create scheduled tasks via Powershell 4.0 on Windows Server 2008 R2? 使用Powershell Windows Server 2008 R2将用户导入本地 - Import users to local with powershell windows server 2008 r2 我可以使用Powershell Server 2008 R2创建dhcp保留吗 - Can I create dhcp reservation with powershell server 2008 r2 如何在Windows 2008 R2域控制器上本地获取有关具有Powershell的RootDSE的信息 - How can I get information about the RootDSE with Powershell locally on a Windows 2008 R2 Domain Controller 如何在 windows 服务器 2008 R2 中获得总虚拟内存 - How can I get total virtual-memory in windows server 2008 R2 Windows Server 2008 R2 PowerShell和Internet Explorer 9 - Windows Server 2008 R2 PowerShell and Internet Explorer 9 更改芬兰语Windows Server 2008 R2上Powershell脚本的文化 - Change culture on Finnish Windows Server 2008 R2 for Powershell Script Windows Server 2008 R2中无法通过Powershell 4导入模块Hyper-V - can't import-module Hyper-V by powershell 4 in windows server 2008 R2 Windows Server 2008 R2使用Powershell编辑网络设置 - Windows Server 2008 R2 editing network settings with powershell 在 Windows Server 2008 R2 上的 PowerShell 中创建专用队列 - Creating private queues in PowerShell on Windows Server 2008 R2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM