简体   繁体   English

在Powershell中的环境选项卡用户adsi中为TSclients添加登录程序

[英]Add logon program for TSclients in environment tab user adsi in Powershell

Hi I'm tring to set a logon program parameter for remote clients that will be created using a powershell script. 嗨,我正在尝试为将使用Powershell脚本创建的远程客户端设置登录程序参数。 As shown below 如下所示

在此处输入图片说明

I managed to get a logon script to set in the profile tab using 我设法使用配置文件选项卡中设置了登录脚本

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

As seed in this thread here 由于在此线程的种子在这里

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 问题是我无法在ADSIedit中找到该属性,而且我使用和工作的某些属性未在ADSIedit中显示,例如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();

It took a long time to figure this one out be found the answer in IADsTSUserEx library 花了很长时间才能在IADsTSUserEx库中找到答案

here is the code below 这是下面的代码

# 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()

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM