Install-User.ps1

function Install-User
{
param(
[Parameter()]
[string]$ComputerName = $env:computername, [Parameter(Mandatory=$true)]
[string]$UserName, [Parameter(Mandatory=$true)]
[string]$Password, [Parameter()]
[bool]$PasswordChangeable = $true, [Parameter()]
[bool]$PasswordExpired = $true, [Parameter()]
[string]$Description, [Parameter()]
[string]$FullName, [Parameter()]
[string]$Group, [Parameter()]
[switch]$PassThru
) Write-Verbose "Installing user '$Username' on '$ComputerName'..." if(!(Test-Connection $ComputerName -Count -Quiet))
{
Write-Error "Unable to connect '$ComputerName'. The network path not found."
return
}
try
{
if([ADSI]::Exists("WinNT://$ComputerName/$UserName"))
{
Write-Error "User '$UserName' is already exist on '$ComputerName'."
return
} if($Group)
{
if(!([ADSI]::Exists("WinNT://$ComputerName/$Group")))
{
Write-Error "Group '$Group' could not be found on '$ComputerName'."
return
}
} #Create User account
$account = ([ADSI]"WinNT://$ComputerName,computer").Create('user',$UserName)
#Set password on account
$account.psbase.invoke("SetPassword",$Password)
#Commit the changes made
$account.psbase.CommitChanges()
#Set description on account
if($Description) { $account.description = $Description }
#Set description on account
if($FullName) { $account.fullname = $FullName }
#Set flag for password to not expire
if(!$PasswordExpired)
{
$ADS_UF_DONT_EXPIRE_PASSWD = 0x10000
$account.userflags = $account.userflags[] -bor $ADS_UF_DONT_EXPIRE_PASSWD
}
#Set flag for not allow user to change password
if(!$PasswordChangeable) {
$ADS_UF_DO_NOT_ALLOW_PASSWD_CHANGE = 0x0040
$account.userflags = $account.userflags[] -bor $ADS_UF_DO_NOT_ALLOW_PASSWD_CHANGE
}
#Commit the changes
$account.psbase.CommitChanges()
Write-Verbose "Creating user '$Username' on '$ComputerName' was successfully." if($Group)
{
#Add account to Local group
$localGroup = [ADSI]"WinNT://$ComputerName/$Group,group"
$localGroup.PSBase.Invoke("Add",$account.PSBase.Path)
Write-Verbose "Adding user '$Username' to group '$Group' on '$ComputerName' was successfully."
} Write-Verbose "User '$Username' has been installed on '$ComputerName'." if($Passthru)
{
$pso = New-Object PSObject -Property @{
ComputerName = $ComputerName.ToUpper()
UserName = $UserName
FullName = $FullName
Description = $Description
PasswordExpired = $PasswordExpired
PasswordChangeable = $PasswordChangeable
Group = $Group
}
$pso.PSTypeNames.Clear()
$pso.PSTypeNames.Add('MKServerBuilder.UserAccount')
$pso
}
}
catch
{
Write-Error $_
}
}

Install-User.ps1的更多相关文章

  1. 【转】Install Win32 OpenSSH (test release)

    Openssh download url:https://github.com/PowerShell/Win32-OpenSSH/releases Install instruction: Insta ...

  2. Powershell script to install Windows Updates (msu) from folder

    ######################################################### # # Name: InstallWindowsUpdates.ps1 # Auth ...

  3. 利用Nuget打包添加tools下intsall.ps1【powershell脚本】修改.csproj文件

    利用Nuget打包添加tools下intsall.ps1[powershell脚本]修改.csproj文件, 以设置1.项目-生成->输出->选择[XML文件文件] 2.项目->调试 ...

  4. 'Install app for SharePoint': Sideloading of apps is not enabled on this site

    http://blog.lekman.com/2012/11/sharepoint-2013-sideloading-of-apps-is.html Solution: You need to ena ...

  5. vue : 无法加载文件 C:\Users\xxx\AppData\Roaming\npm\vue.ps1

    最近因为电脑太卡,小颖把电脑重装了,重装后再执行 npm install -g @vue/cli 时可能是网络问题,一直不能成功,小颖就把npm指向了淘宝镜像: npm install -g cnpm ...

  6. Install chocolatey

    Requirements Windows 7+ / Windows Server 2003+ PowerShell v2+ .NET Framework 4+ (the installation wi ...

  7. 解决npm : 无法加载文件 D:\Code\renren-fast-vue\node_modules\.bin\npm.ps1,因为在......

    解决这个问题: 看看错误信息: npm : 无法加载文件 D:\DevPath\nodejs\npm.ps1,因为在此系统上禁止运行脚本.有关详细信息,请参阅 https:/go.microsoft. ...

  8. OEL上使用yum install oracle-validated 简化主机配置工作

    环境:OEL 5.7 + Oracle 10.2.0.5 RAC 如果你正在用OEL(Oracle Enterprise Linux)系统部署Oracle,那么可以使用yum安装oracle-vali ...

  9. org.jboss.deployment.DeploymentException: Trying to install an already registered mbean: jboss.jca:service=LocalTxCM,name=egmasDS

    17:34:37,235 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080 17:34:37,281 INFO [ ...

  10. 如何使用yum 下载 一个 package ?如何使用 yum install package 但是保留 rpm 格式的 package ? 或者又 如何通过yum 中已经安装的package 导出它,即yum导出rpm?

    注意 RHEL5 和 RHEL6 的不同 How to use yum to download a package without installing it Solution Verified - ...

随机推荐

  1. 【Hihocoder 1167】 高等理论计算机科学 (树链的交,线段树或树状数组维护区间和)

    [题意] 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 少女幽香这几天正在学习高等理论计算机科学,然而她什么也没有学会,非常痛苦.所以她出去晃了一晃,做起了一些没什么意 ...

  2. apache整合tomcat部署集群

    近日,由于公司项目需要,所以学习了apache整合tomcat以及集群的一些知识. 所以做下笔记日后回顾可以用到. apache只有处理静态事物的能力, 而tomcat的强项就是处理动态的请求,所以a ...

  3. [wikioi]没有上司的舞会

    树形DP.用F[k][0]和F[k][1]表示某节点不选和选了之后子树的最大值.那么:f[i][0]=sigma(max(f[k][0],f[k][1]))f[i][1]=sigma(f[k][0]) ...

  4. SPRING IN ACTION 第4版笔记-第二章-001-用@Autowired\@ComponentScan、@Configuration、@Component实现自动装载bean

    1. package soundsystem; import org.springframework.context.annotation.ComponentScan; import org.spri ...

  5. Listview 异步加载图片之优化篇(有图有码有解释)

    在APP应用中,listview的异步加载图片方式能够带来很好的用户体验,同时也是考量程序性能的一个重要指标.关于listview的异步加载,网上其实很多示例了,中心思想都差不多,不过很多版本或是有b ...

  6. 便利的html5 之 required、number 、pattern

    html5对于表单验证提供了很多自识别功能,非常的便利. 看代码, <!--head start--> <include file="Public:head" / ...

  7. Unity3D-基本导航(NavMesh)功能实现

    1: 打开场景 2:打开Navgation窗口 菜单中: Window --> Navgation, 在Inspector旁边会出现导航界面 这个Objcet的面板是对应当前选择的物体的,旁边的 ...

  8. CentOS升级Python的方法

    centOS内核版本为:3.10.101-1.el6.elrepo.x86_64 1,下载Python安装包 wget http://www.python.org/ftp/python/2.7.6/P ...

  9. IIS 7.0, ASP.NET, pipelines, modules, handlers, and preconditions

    1.0 What is the IIS Pipeline Conceptually, the IIS pipeline is a state machine with the following st ...

  10. 如何让虚拟目录里面的webconfig不继承网站的设置

    在一个网站 中国红木网 下 建一个虚拟目录,结果虚拟目录系统会调用 中国红木网 上的web.config, 在网上找到以下解决方案 在(如根目录)所在的Web.config加上 如:<locat ...