ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell - Logoff disconnected sessions

    IT Discussion
    powershell scripting rdp sessions
    2
    4
    1.8k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • hobbit666H
      hobbit666
      last edited by hobbit666

      I'm trying to write something that will go through our Citrix server and "log off" all the disconnected sessions.

      I can do this fine manually through PowerShell fine and works, but now I want to automate it so I can run it or even schedule it to run every X minutes/hours.

      (Just trying it on 1 servers at the moment, I'm outputting the array(s) etc to check the results of the commands.
      )

      $servername = "xen30"
      $pc = qwinsta /server:$servername | select-string "Disc" | select-string -notmatch "services"
      $pc
      That gives me a array :-

      crav2 878 Disc
      ryan 881 Disc
      lanc4 885 Disc
      clive 888 Disc
      treg1 889 Disc
      rob 891 Disc
      paul 892 Disc
      New2 893 Disc

      The command i'm using is
      logoff <id> /server:$servername

      So what I need to do is "extract" the 2nd colum form the $pc list that gives me a list of id's then I guess use the foreach command to "inject" the ids into the logoff command.

      1 Reply Last reply Reply Quote 2
      • JaredBuschJ
        JaredBusch
        last edited by

        You use split.

        https://blogs.technet.microsoft.com/heyscriptingguy/2014/07/17/using-the-split-method-in-powershell/

        1 Reply Last reply Reply Quote 0
        • JaredBuschJ
          JaredBusch
          last edited by

          or this.
          https://4sysops.com/archives/strings-in-powershell-replace-compare-concatenate-split-substring/#splitting-strings

          1 Reply Last reply Reply Quote 0
          • hobbit666H
            hobbit666
            last edited by

            not having much luck...... It's Friday so giving up till Monday/Tuesday 🙂

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post