在Powershell中的环境选项卡用户adsi中为TSclients添加登录程序 [英] Add logon program for TSclients in environment tab user adsi in Powershell

查看:189
本文介绍了在Powershell中的环境选项卡用户adsi中为TSclients添加登录程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我想为将使用Powershell脚本创建的远程客户端设置登录程序参数。如下所示

Hi I'm tring to set a logon program parameter for remote clients that will be created using a powershell script. As shown below

我设法使用$ p

I managed to get a logon script to set in the profile tab using

$objUser.PSBase.InvokeSet('LoginScript', "logoff.cmd")

作为种子此线程此处

问题是我在ADSIedit中找不到属性,在ADSIedit中也没有显示我使用和工作的某些属性,例如PasswordExpired

The problem is I can't find the attribes in ADSIedit also some attrribes that I use and work aren't shown in ADSIedit such as PasswordExpired

相信该属性确实存在。下面是我的代码

which leads me to believe the attribute does exsist. Below is my code

$objComputer = [ADSI]"WinNT://127.0.0.1"
$objUser = $objComputer.Create('user', $username)
$objUser.SetPassword($password)
$objUser.PSBase.InvokeSet('Description', "user " + $userName)
$objUser.PSBase.InvokeSet('userflags', 512)
$objUser.PSBase.InvokeSet('passwordExpired', 1)
$objUser.SetInfo();


推荐答案

花了很长时间才能弄清楚在 IADsTSUserEx

It took a long time to figure this one out be found the answer in IADsTSUserEx library

这是下面的代码

# adds user
$objComputer = [ADSI]"WinNT://127.0.0.1"
$objUser = $objComputer.Create('user', $username)
$objUser.SetPassword($password)
$objUser.PSBase.InvokeSet('Description', "user " + $userName)
$objUser.PSBase.InvokeSet('userflags', 512)
$objUser.SetInfo();
# set password not to expire
wmic USERACCOUNT WHERE "Name = '$username'" SET Passwordexpires=FALSE
#set logoff script
$ou = [adsi]"WinNT://127.0.0.1"
$user = $ou.psbase.get_children().find("test")
$user.PSBase.InvokeSet("TerminalServicesInitialProgram", "C:\logoff.bat")
$user.setinfo()

这篇关于在Powershell中的环境选项卡用户adsi中为TSclients添加登录程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆