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

后端 未结 1 329
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 20:12

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

相关标签:
1条回答
  • 2021-01-15 20:38

    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()
    
    0 讨论(0)
提交回复
热议问题