Add logon program for TSclients in environment tab user adsi in Powershell

一世执手 提交于 2019-12-30 12:21:26

问题


Hi I'm tring to set a logon program parameter for remote clients that will be created using a powershell script. 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

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

回答1:


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

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


来源:https://stackoverflow.com/questions/12108898/add-logon-program-for-tsclients-in-environment-tab-user-adsi-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!