Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Passthru with quser

$
0
0

#When I execute quser.exe from the command line one of the fields is labelled ID. If in powershell I assign a variable to exectuting quser.exe and use the get-member to query the results of executing quser.exe one of the properties #returned is ID. ie $quser = Start-Process -FilePath "$program" -PassThru

But if I run a foreach loop ,ie foreach ($person in    $quser) the $person.id is not the session id.

#------------------------------script below

# logoff remote users
# pass in results from quser.exe command
#use id property to select user to logoff



 $program="s:\windows\system32\quser.exe"

 $quser = Start-Process -FilePath "$program" -PassThru

$logoff_program="s:\windows\system32\logoff.exe"
$logoff_arguments= "$quser.id"    


    foreach ($person in    $quser)
    {
    $arguments= "$person.id"
    write-host $person.id
    Start-process -FilePath "$logoff_program" -ArgumentList "$logoff_arguments" }

  

Paul Karrel Trent University



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>